Running PHP 5.2 and 5.3 On The Same Server

Even though most of PHP applications is now running with PHP version 5.3, there are a few PHP applications are still running on PHP version 5.2, you can see what makes that thing happens here: http://php.net/manual/en/migration53.incompatible.php

So i guess it will be good for PHP programmer / developer to have PHP version 5.2 and 5.3 installed and running on the same machine (more economical than using two machines for each PHP version). So let’s get started.

Anyway i will use NginX as the webserver, so the main principle of two PHP version running on the same machine is CGI works using different localhost port.

Before installing PHP, we usually install webserver and database first, i assume that you all have installed NginX and MySQL, so i just skip to the PHP installation.

note: the configuration below is my usual config and dependencies, if you are experiencing error while configure or make php, try to find out about the missing dependencies by looking at this blog’s older posts or googling. The first four configuration of PHP will be the important note because we will separate PHP 5.3 and 5.2 configuration (php.ini) path.

--prefix=/usr/local53 --libdir=/usr/local53/lib --with-libdir=lib --with-config-file-path=/usr/local53/lib
--prefix=/usr/local52 --libdir=/usr/local52/lib --with-libdir=lib --with-config-file-path=/usr/local52/lib

Install PHP 5.3.8 with PHP-FPM

wget http://pkgs.serversreview.net/files/autoconf-2.13.tar.gz
tar -zxvf autoconf-2.13.tar.gz
cd autoconf-2.13
./configure
make && make install

wget http://pkgs.serversreview.net/files/php-5.3.8.tar.gz
tar -zxvf php-5.3.8.tar.gz
cd php-5.3.8
./buildconf --force
./configure --prefix=/usr/local53 --libdir=/usr/local53/lib --with-libdir=lib --with-config-file-path=/usr/local53/lib --enable-force-cgi-redirect --enable-fpm --enable-cli --with-mcrypt --enable-mbstring --with-openssl --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/var/lib/mysql/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-zlib --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-png --with-jpeg --with-gmp --with-sqlite --enable-pdo --with-xpm-dir=/usr/lib --with-freetype-dir=/usr/include/freetype2 --with-ttf=/usr/include/freetype2 --enable-gd-native-ttf --enable-fileinfo --disable-debug --with-pic --with-bz2 --with-curl --with-curlwrappers --without-gdbm --with-gettext --with-iconv --with-pspell --with-pcre-regex --with-imap --with-imap-ssl=/usr/lib --enable-exif --enable-ftp --enable-magic-quotes --enable-sockets --disable-sysvsem --disable-sysvshm --disable-sysvmsg --enable-track-vars --enable-trans-sid --enable-yp --enable-wddx --with-kerberos --enable-ucd-snmp-hack --enable-memory-limit --enable-shmop --enable-calendar --enable-dbx --enable-dio --with-mime-magic --with-system-tzdata --with-odbc --enable-gd-jis-conv --enable-dom --disable-dba --enable-xmlreader --enable-xmlwriter --with-tidy  --with-xml --with-xmlrpc --with-xsl --enable-bcmath --enable-soap --enable-zip --enable-inline-optimization --with-mhash --enable-mbregex
make
make install

cp php.ini-production /usr/local53/lib/php.ini


Install PHP 5.2.17 with PHP-FPM patch

wget http://pkgs.serversreview.net/files/libevent-2.0.16-stable.tar.gz
tar -zxvf libevent-2.0.16-stable.tar.gz
cd libevent-2.0.16-stable
./configure --prefix=/usr --libdir=/usr/lib
make
make install

wget http://pkgs.serversreview.net/files/php-5.2.17.tar.gz
tar -zxvf php-5.2.17.tar.gz
cd php-5.2.17
wget http://pkgs.serversreview.net/files/php-5.2.17-fpm-0.5.14.diff.gz
gunzip php-5.2.17-fpm-0.5.14.diff.gz
patch -p1 < php-5.2.17-fpm-0.5.14.diff
./configure --prefix=/usr/local52 --libdir=/usr/local52/lib  --with-libdir=lib --with-config-file-path=/usr/local53/lib --enable-force-cgi-redirect --enable-fastcgi --enable-fpm --with-libevent=/usr/lib --enable-cli --with-mcrypt --enable-mbstring --with-openssl --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/var/lib/mysql/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-zlib --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --enable-zend-multibyte --with-png --with-jpeg --with-gmp --with-sqlite --enable-pdo --with-xpm-dir=/usr/lib --with-freetype-dir=/usr/include/freetype2 --with-ttf=/usr/include/freetype2 --enable-gd-native-ttf --with-mime-magic --disable-debug --with-pic --with-bz2 --with-curl --with-curlwrappers --without-gdbm --with-gettext --with-iconv --with-pspell --with-pcre-regex --with-imap --with-imap-ssl=/usr/lib --enable-exif --enable-ftp --enable-magic-quotes --enable-sockets --disable-sysvsem --disable-sysvshm --disable-sysvmsg --enable-track-vars --enable-trans-sid --enable-yp --enable-wddx --with-kerberos --enable-ucd-snmp-hack --enable-memory-limit --enable-shmop --enable-calendar --enable-dbx --enable-dio --with-mime-magic --with-system-tzdata --with-odbc --enable-gd-jis-conv --enable-dom --disable-dba --enable-xmlreader --enable-xmlwriter --with-tidy  --with-xml --with-xmlrpc --with-xsl --enable-bcmath --enable-soap --enable-zip --enable-inline-optimization --with-mhash --enable-mbregex --enable-memcache
make
make install
strip /usr/bin/php-cgi
sed -i 's/extension_dir/;extension_dir/g' php.ini-recommended
cp php.ini-recommended /usr/local52/lib/php.ini

Next the configuration for php-fpm.conf PHP 5.3 and 5.2, the point you need to take a look is localhost and listen port

Version 5.3

mv /usr/local53/etc/php-fpm.conf.default /usr/local53/etc/php-fpm.conf
nano /usr/local53/etc/php-fpm.conf

check listening port and set it to 9000, also don’t forget to change user and group to www

user = www
group = www
listen = 127.0.0.1:9000

Version 5.2

nano /usr/local52/etc/php-fpm.conf

check listening port and set it to 9001, change user and group to www

name=listen_address 127.0.0.1:9001
name=user www
name=group www

I am using “www“user and group for NginX and PHP, the rest setting for PHP 5.3 and 5.2 is yours.

Now we create init script for both PHP-FPM 5.3 and 5.2

Init script 5.3

nano /etc/rc.d/init.d/php-fpm53
case "$1" in
	start)
		/usr/local53/sbin/php-fpm --fpm-config /usr/local53/etc/php-fpm.conf
		echo "PHP-FPM started successfully"
		exit 1
	;;

	stop)
		pkill php-fpm
		echo "PHP-FPM stopped"
		exit 1
	;;
	restart)
		echo "Stopping php-fpm"
		pkill php-fpm
		sleep 2
		echo "Starting php-fpm"
		/usr/local53/sbin/php-fpm --fpm-config /usr/local53/etc/php-fpm.conf
		echo "PHP-FPM restarted successfully"
		exit 1
	;;
	*)
		echo "Usage: start - stop - restart"
		exit 1
	;;
esac

Init script 5.2

ln -s /usr/local52/sbin/php-fpm /etc/init.d/php-fpm

make those init scripts executable

chmod +x /etc/init.d/php-fpm53 /etc/init.d/php-fpm52

Now let’s start both init scripts

/etc/init.d/php-fpm53 start
/etc/init.d/php-fpm52 start

Check both PHP 5.3 and 5.3 binary files if they are already running

ps aux

php 5.3 and 5.2 running together

Okay PHP 5.3 and 5.2 is now running together on the same machine, last thing you have to do is determine whether you want to use PHP 5.3 or 5.2 or both, here is the example of virtual host configuration using serversreview.net as domain.

user www www;
.....
.....
http {
	  server {
	  listen 80;
	  server_name serversreview.net;
	  access_log /home/www/serversreview.net/logs/access.log;
	  error_log /home/www/serversreview.net/logs/error.log;

	  location / {
		root /home/www/serversreview.net/public_html/;
		index index.html index.htm index.php;
	  }

	  location ~ \.php$ {
		include /etc/nginx/fastcgi_params;
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME /home/www/serversreview.net/public_html$fastcgi_script_name;
	  }
	}
}

you just need to switch the port 9000 for PHP version 5.3 and 9001 for PHP version 5.2 in this line

fastcgi_pass 127.0.0.1:9000;

That’s it! You are ready to roll your machine with PHP 5.3 and 5.2, if there is something you don’t understand or error while you are setting this up, remember that Google is your first aid, or we can discuss toghether about your confusion here. 😀

{ 0 comments }

2 thoughts on “Running PHP 5.2 and 5.3 On The Same Server

    1. yes perhaps it should be, but you can try the tutorial and tell me if it is work or not 😀

Leave a Reply

Your email address will not be published. Required fields are marked *