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.
Installation
EDIT: 1
- added some new dependencies: libicu-dev g++ libmysqlclient-dev
First some dependencies:
#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:
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:
# 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:
make -j4
# installing the binaries
make install
#or
make install -k
# -k will allow you to process the installation even if there are Apache related errors
By default this installation should look for config files here:
# and
$PARENT_FOLDER_LOCATION/php.ini
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:
#copy here ubuntu php 5.3 configs from you local machine which are located in /etc/php5/cgi/conf.d/ folder if you plan on using FastCGI
#copy here ubuntu php 5.3 php.ini from here /etc/php5/cgi/
If you are using FastCGI , DISABLE PATH RESOLUTION / FIXING (!!!) because it will allow to execute code from images or other uploaded files with urls like this “http://example.com/images/foo/hacker.jpg/test/fake.php”.
vi $PARENT_FOLDER_LOCATION/php.ini
#####
...
cgi.fix_pathinfo=0
...
#####
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/:
root root 4096 Aug 5 19:50 ..
root root 69 Aug 4 02:26 bin
root root 77 Aug 4 03:35 conf.d
root root 16 Aug 4 02:08 include
root root 16 Aug 4 02:08 lib
root root 17 Aug 4 02:09 man
root root 67594 Aug 4 03:28 php.ini
The $PARENT_FOLDER_LOCATION/bin should look like this:
root root 77 Aug 4 03:25 ..
root root 32 Aug 4 02:26 php -> /usr/local/php5.3/bin/php-cgi5.3
root root 31487388 Aug 4 02:08 php-cgi5.3
root root 3612 Aug 4 02:09 php-config5.3
root root 4516 Aug 4 02:09 phpize5.3
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.
Suchosin extension
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:
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:
PHP 5.3.6 (cgi-fcgi) (built: Aug 4 2011 02:07:49)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
The ” with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH” line will tell you if Suhosin is installed properly.
Possible issues with the installation
Apache related error:
apxs:Error: Activation failed for custom /etc/apache2/httpd.conf file.. apxs:Error: At least one `LoadModule’ directive already has to exist.. make[2]: *** [mod_xmlent-install] Error 1 make[1]: *** [mod_xmlent-install] Error 2
Fix:
vi $PARENT_FOLDER_LOCATION/etc/apache2/httpd.conf
######
# dummy comment
LoadModule dummy_module /usr/lib/apache2/modules/mod_dummy.so
LoadModule mod_xmlent /usr/lib/apache2/modules/mod_xmlent.so
######
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:
Related tasks
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
Leave a Reply