Ce guide n’est qu’une mise à jour de notre guide sur la compilation de php-5.3.10

We planned this guide for php 5.3.9, but as php 5.3.10 was released less than a week later, we decided to skip one version and do this guide for the newest version.

This article worked for us, however, neither will the author or Open Skill be taken for responsable for any negative consequences this tutorial could have.

Our method has the following advantages:

  • You can easily install concurrent versions of php on one machine,
  • It offers you a per site choice of version,
  • Ideal to test a new version on a server without compromising every site’s stability.

The main inconvenient is that as a custom php, it will be ignored by your system updates.
Let’s go in the home directory:

$ cd ~

Install the dependencies we could need:

$ sudo yum install -yq gcc libicu-devel libxml2-devel mysql-devel libpng-devel libjpeg-devel curl-devel bzip2-devel gettext-devel gmp-devel pcre-devel freetype-devel gd-devel aspell-devel db4-devel libxslt-devel php-xml libtidy.i3106 libtidy-devel.i3106 libmemcached gcc-c++ libevent libevent-devel.i3106 ImageMagick.i3106 ImageMagick-devel.i3106

Get php’s latest archive and decompress it:

$ wget http://be.php.net/distributions/php-5.3.10.tar.gz
$ tar -xzf php-5.3.10.tar.gz

Move it to home and go there:

$ sudo mv php-5.3.10 /home/version-5.3.10
$ cd /home/version-5.3.10

Create the required directories:

$ mkdir -p usr/local/5310 etc/5310 etc/5310.d

Launch ./configure – You should modify this line according to your needs, patience, this step can take time!

$ ./configure --prefix=/home/version-5.3.10/usr/local/5310 --with-config-file-path=/home/version-5.3.10/etc/5310 --with-config-file-scan-dir=/home/version-5.3.10/etc/5310.d --with-bz2 --with-db4=/usr --with-curl --with-exec-dir=/usr/bin --with-freetype-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --without-gdbm --with-gettext --with-gmp --with-iconv --with-jpeg-dir=/usr --with-openssl --with-pspell --with-pcre-regex=/usr --with-zlib --with-layout=GNU --enable-exif --enable-ftp --enable-magic-quotes --enable-sockets --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-wddx --with-kerberos --enable-ucd-snmp-hack --enable-shmop --enable-calendar --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --with-libxml-dir=/usr --with-gd=/usr --with-regex=system --with-xsl=/usr --enable-mbstring --with-pic --without-sqlite --with-tidy --enable-zip

If everything went ok, php is configured to be compiled on your system: lets compile it. Patience, this step takes more time than the previous one :p

$ gmake

Now that it is compiled, we should put a php.ini and configure it according to our needs:

$ cp /home/version-5.3.10/php.ini-production /home/version-5.3.10/etc/5310/php.ini
$ nano /home/version-5.3.10/etc/5310/php.ini

Let’s install it

$ gmake install

Now that php is installed, let’s add pear:

$ mkdir -p /home/version-5.3.10/usr/local/5310/share/pear/
$ cd /home/version-5.3.10/usr/local/5310/share/pear/

While installing pear, you will be asked two questions, answer 1 and then /home/version-5.3.10/usr/local/5310

$ wget http://pear.php.net/go-pear.phar
$ cat go-pear.phar | /home/version-5.3.10/usr/local/5310/bin/php
$ cd /home/version-5.3.10/

Restart httpd:

$ sudo /etc/init.d/httpd restart

We observed a few configuration problems during an upgrade and advice you to check the paths with the following command:

$ /home/version-5.3.10/usr/local/5310/bin/pear config-show


If some directories are not correct, correct them with the right commands (adapt according to the case):

$ /home/version-5.3.10/usr/local/5310/bin/pear config-set bin_dir /home/version-5.3.10/usr/local/5310/bin
$ /home/version-5.3.10/usr/local/5310/bin/pear config-set doc_dir /home/version-5.3.10/usr/local/5310/docs
$ /home/version-5.3.10/usr/local/5310/bin/pear config-set php_dir /home/version-5.3.10/usr/local/5310/share/pear
$ /home/version-5.3.10/usr/local/5310/bin/pear config-set cfg_dir /home/version-5.3.10/usr/local/5310/cfg
$ /home/version-5.3.10/usr/local/5310/bin/pear config-set data_dir /home/version-5.3.10/usr/local/5310/data
$ /home/version-5.3.10/usr/local/5310/bin/pear config-set test_dir /home/version-5.3.10/usr/local/5310/tests
$ /home/version-5.3.10/usr/local/5310/bin/pear config-set www_dir /home/version-5.3.10/usr/local/5310/www

 

Now we can install extra modules to our new php:
This command is mandatory to install pecl extensions, don’t forget to remount the tmp partition in noexec later as it exec mode lowers the security.

$ sudo mount -o remount,exec /tmp

Download, extract and intall json:

$ wget http://pecl.php.net/get/json-1.2.1.tgz
$ tar -xvzf json-1.2.1.tgz
$ rm json-1.2.1.tgz
$ cd json-1.2.1
$ /home/version-5.3.10/usr/local/5310/bin/phpize
$ ./configure --with-php-config=/home/version-5.3.10/usr/local/5310/bin/php-config --prefix=/home/version-5.3.10/usr/local/5310/ --with-json
$ make
$ make install
$ cd ../
$ sudo /home/version-5.3.10/usr/local/5310/bin/pecl install json

! Add the extension=json.so line to your php.ini to load the module !

$ echo "extension=json.so" >> /home/version-5.3.10/etc/5310/php.ini

Install memcache:

$ sudo /home/version-5.3.10/usr/local/5310/bin/pecl install memcache

! Add the extension=memcache.so line to your php.ini to load the module !

$ echo "extension=memcache.so" >> /home/version-5.3.10/etc/5310/php.ini

Download, compile and install memcached

$ wget http://memcached.googlecode.com/files/memcached-1.4.7.tar.gz
$ tar -xzf memcached-1.4.7.tar.gz
$ cd memcached-1.4.7
$ ./configure --prefix=/home/version-5.3.10/usr/local/5310/
$ make
$ make install
$ cd ..
$ sudo echo "/usr/local/lib/" >> /etc/ld.so.conf.d/libevent-i3106.conf
$ sudo ldconfig

! ! ! Carefull to take different ports for different memcaches! ! !

$ sudo /home/version-5.3.10/usr/local/5310/bin/memcached -d -u nobody -m 1024 127.0.0.1 -p 11211
$ sudo touch /etc/init.d/memcached-version-5.3.10
$ sudo echo '#!/bin/sh -e' >> /etc/init.d/memcached-version-5.3.10
$ sudo echo '/home/version-5.3.10/usr/local/5310/bin/memcached -d -m 512 -p 11211 -u nobody -l localhost' >> /etc/init.d/memcached-version-5.3.10
$ sudo chmod u+x /etc/init.d/memcached-version-5.3.10
$ sudo echo '/etc/init.d/memcached-version-5.3.10' >> /etc/rc.local
$ cd ../

Install libmemcached:

$ wget http://launchpadlibrarian.net/731043684/libmemcached-0.50.tar.gz
$ tar -xvzf libmemcached-0.50.tar.gz
$ cd libmemcached-0.50

An error in the sources prevents us to compile libmemcached on a 32 bit architecture, that’s why in the clients/memcapable.cc file at lines 658, 728 and 787, the value “0xdeadbeefdeadcafe” should be replaced by “0xdeadbeefdeadcafeULL”. After that the compilation works as a charm (NB: When writing this article, there where more recent versions of libmemcached but they couldn’t compile because CentOS 5 version of autoconf is too old.

$ nano +658 clients/memcapable.cc
$ ./configure --without-memcached --disable-64bit --prefix=/home/version-5.3.10/usr/local
$ make
$ make install
$ cd ..
$ sudo /home/version-5.3.10/usr/local/5310/bin/pecl install memcached

! Add the extension=memcached.so line to your php.ini to load the module !

$ echo "extension=memcached.so" >> /home/version-5.3.10/etc/5310/php.ini
$ sudo /home/version-5.3.10/usr/local/5310/bin/pecl install imagick

! Add the extension=imagick.so line to your php.ini to load the module !

$ echo "extension=imagick.so" >> /home/version-5.3.10/etc/5310/php.ini
$ sudo /home/version-5.3.10/usr/local/5310/bin/pecl install zip

! Add the extension=zip.so line to your php.ini to load the module !

$ echo "extension=zip.so" >> /home/version-5.3.10/etc/5310/php.ini

Download, compile and install tidy:

$ wget http://pecl.php.net/get/tidy-1.2.tgz
$ tar -xvzf tidy-1.2.tgz
$ rm tidy-1.2.tgz
$ cd tidy-1.2
$ /home/version-5.3.10/usr/local/5310/bin/phpize
$ ./configure --with-php-config=/home/version-5.3.10/usr/local/5310/bin/php-config --prefix=/home/version-5.3.10/usr/local --with-tidy
$ make
$ make install
$ cd ..

! Add the extension=tidy.so line to your php.ini to load the module !

$ echo "extension=tidy.so" >> /home/version-5.3.10/etc/5310/php.ini

!Once all the plugins are installed, we remount /tmp in noexec as said earlier!

$ sudo mount -o remount,noexec /tmp

Now you just have to activate php on a site by putting 3 lines in the site’s vhost file (example for site1):


$ sudo echo "ScriptAlias /5310-cgi /home/version-5.3.10/usr/local/5310/bin/php-cgi" >> /etc/httpd/conf/vhosts/site1.include
$ sudo echo "Action application/x-http-5310 /5310-cgi" >> /etc/httpd/conf/vhosts/site1.include
$ sudo echo "AddHandler application/x-http-5310 .php" >> /etc/httpd/conf/vhosts/site1.include

Restart apache


$ sudo /etc/init.d/httpd restart

If everything happened as planned, you should just test your site with an info.php.

Don’t hesitate to send us your comments or corrections for this tutorial.