In this article I will show you how to compile php 5.3 on Ubuntu 8.04 but it should work in a similar manner on later distributions.
- added some new dependencies: libicu-dev g++ libmysqlclient-dev
First some dependencies:
apt-get install make gcc autoconf bison re2c libxpm-dev libsasl2-dev libpspell-dev libreadline5-dev libsnmp-dev #apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev apache2-utils apache2.2-common apt-get install aspell libaspell-dev libxml2 libsnmp-base libsnmp15 libxml2-dev apt-get install libbz2-dev libzip-dev libzip1 zlib1g zlib1g-dev apt-get install curl libcurl4-openssl-dev libcurl3 libcurl3-gnutls apt-get install libc-client-dev libfreetype6 libfreetype6-dev apt-get install libjpeg62 libjpeg62-dev libpng12-0 libpng12-dev apt-get install libmcrypt-dev libmcrypt4 libtidy-dev libxslt1-dev libicu-dev g++ libmysqlclient-dev # for /usr/bin/apxs2 #aptitude install apache2-threaded-dev apache2-utils apache2.2-common aptitude install libicu-dev libicu38 #aptitude install mysql-server-core-5.0 #aptitude install mysql-common mysql-server mysql-server-5.0 mysql-client mysql-client-5.0 mysql-server-core-5.0
I have commented out the the dependencies which are needed for compiling the apache2 module because in this post I want to show you how to get the the php5-cgi binary which is a bit tricky because you can't compile all binaries at once and you need to know which options to disable to get the CGI .
No we are going to need the php's source code:
# go to your source directory cd /usr/local/src #remove previous source folder if needed rm -rf php-5.3.6 #fetch the latest source wget http://uk.php.net/distributions/php-5.3.6.tar.gz # -o means that we wont preserve the owner, there is also --no-same-permissions tar -oxzf php-5.3.6.tar.gz cd php-5.3.6 # with this command you can apply appropriate ownership rights # if you skip the -o paramater above # chown -R root:root
Now lets prepare the source for compilation:
#if recompiling # make clean # you can display configuration options # ./configure --help #removed options # --disable-short-tags \ # --with-apxs2=/usr/bin/apxs2 \ # --enable-fpm \ # --with-fpm-user=phpfpm \ # --with-fpm-group=phpfpm \ PARENT_FOLDER_LOCATION=/usr/local/php5.3 ./configure --prefix=$PARENT_FOLDER_LOCATION \ --with-config-file-path=$PARENT_FOLDER_LOCATION \ --with-config-file-scan-dir=$PARENT_FOLDER_LOCATION/conf.d \ --program-suffix=5.3 \ --disable-cli \ --enable-cgi \ --enable-inline-optimization \ --enable-mbregex \ --with-pcre-regex \ --with-pear \ --enable-intl \ --without-t1lib \ --enable-pcntl \ --with-tsrm-pthreads \ --with-mysqli=mysqlnd \ --with-mysql=mysqlnd \ --with-pdo-mysql \ --with-openssl \ --with-zlib \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-bcmath \ --with-bz2 \ --enable-calendar \ --enable-exif \ --enable-ftp \ --with-gd \ --with-jpeg-dir=$PARENT_FOLDER_LOCATION/usr/lib \ --with-png-dir=$PARENT_FOLDER_LOCATION/usr/lib \ --with-xpm-dir=$PARENT_FOLDER_LOCATION/usr/lib \ --enable-gd-native-ttf \ --enable-gd-jis-conv \ --with-iconv-dir \ --with-gettext \ --with-imap \ --with-imap-ssl \ --with-ldap \ --with-ldap-sasl \ --enable-mbstring \ --with-mcrypt \ --with-mhash \ --with-pspell \ --with-readline \ --with-snmp \ --enable-soap \ --enable-sockets \ --with-sqlite \ --enable-sqlite-utf8 \ --enable-wddx \ --with-xmlrpc \ --with-xsl \ --enable-zip \ --with-kerberos \ --with-tidy \ --with-curl \ --with-curlwrappers
Lets compile the code now:
By default this installation should look for config files here:
To make your life easier it is best to copy your configs from a distribution which allows installation of php 5.3 , for e.g Ubuntu 10.04:
If you are using FastCGI , <strong>DISABLE PATH RESOLUTION / FIXING (!!!) </strong>because it will allow to execute code from images or other uploaded files with urls like this <strong>"http://example.com/images/foo/hacker.jpg/test/fake.php"</strong>.
If you would try to install some additional extensions through PEAR it will complain about not being able to find php binary so to solve this you can do this:
but it might collide with your other php binary files, depending on your system $PATH settings
After the installation all your files should be in $PARENT_FOLDER_LOCATION which in my case was /usr/local/php5.3/:
The $PARENT_FOLDER_LOCATION/bin should look like this:
as you can see the php-cgi5.3 is quite big (~32MB) because all the extensions are compiled into the binary, but a regular php-cgi file from an Ubuntu installation is around 9MB so it is not much of a problem because you get the benefit of simplicity of the installation.
To make this installation more secure you will need the Suhosin Extension (not patch, there is no patch for php 5.3.6 as of yet).
This is how you can install it:
cd /usr/local/src wget http://download.suhosin.org/suhosin-0.9.32.1.tar.gz tar -ozxf suhosin-0.9.32.1.tar.gz cd suhosin-0.9.32.1 #run this in suhosin's folder /usr/local/php5.3/bin/phpize5.3 ./configure --prefix=$PARENT_FOLDER_LOCATION --with-php-config=$PARENT_FOLDER_LOCATION/bin/php-config5.3 --enable-suhosin --includedir=$PARENT_FOLDER_LOCATION/include make make install
after this installation you should be able to check if it is properly installed with this command or through the phpinfo() page:
The " with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH" line will tell you if Suhosin is installed properly.
<h2>Possible issues with the installation</h2>
Apache related error:
<blockquote> apxs:Error: Activation failed for custom /etc/apache2/httpd.conf file.. apxs:Error: At least one `LoadModule' directive already has to exist.. make: *** [mod_xmlent-install] Error 1 make: *** [mod_xmlent-install] Error 2 </blockquote>
I have tried this quick fix with a single LoadModule line but it doesn't seem to work.
If after the installation PHP would complain about not being able to load some extensions, use this fix:
After you installed new php binaries don't forget to double check your new config files to prepare them for the production environment , especially fine tune your Suhosin settings because the default values are pretty "tight" and will block your file uploads above 1MB I think , max POST attributes , max request size , any many other things.
Using details from this post you should be able to modify them to get the php-cli and php-fcm binarires but remember that each of those binaries needs to be compiled with separate settings (you cant compile all binaries at once) and compiling an apache 2 module is a pain :)
If you have any problems with the installation , please leave a comment below :)
comments powered by Disqus