Compile PHP4 And PHP5 On Same Server

php4-php5

PHP has now been widely used as a development platform for web-based applications. As PHP is in continued development process, we observe different enhancements in PHP itself. One of the major changes we have recently observed is the release of its new version PHP5. 

Now your application is developed in PHP4 and you want to upgrade it to PHP5, but you also want to test it on PHP5 first.

In this post I am going to explain you the method to run both PHP4 and PHP5 on a single Apache server, and you will not need another server which can be dedicated for testing the PHP5 code.

First Download both versions of PHP i.e PHP4 and PHP5 as follows

cd /usr/src/

wget http://www.php.net/get/php-4.4.9.tar.gz/from/jp.php.net/mirror
wget http://www.php.net/get/php-5.3.1.tar.bz2/from/jp.php.net/mirror/

Then issue following command to install PHP4

cd php4.4.9 
'./configure' '--enable-xslt' '--with-xslt-sablot=shared' '--prefix=/usr/local/php4' '--with-expat-dir=/usr/' '--with-apxs2=/usr/sbin/apxs' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-shmop' '--with-curl' '--enable-exif' '--with-dom' '--with-openssl' '--with-zlib' '--with-gd=/usr/local/gd' '--with-clamav' '--enable-ftp' '--enable-sockets' '--enable-exif' '--with-pdflib=shared' '--with-mysql' 
make && make install 

After successfully installing of PHP4 now issue following command to install PHP5

cd php5.3.1 
'./configure' '--enable-xslt' '--with-xslt-sablot=shared' '--prefix=/usr/local/php5' '--with-expat-dir=/usr/' '--with-apxs2=/usr/sbin/apxs' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-shmop' '--with-curl' '--enable-exif' '--with-dom' '--with-openssl' '--with-zlib' '--with-gd=/usr/local/gd' '--with-clamav' '--enable-ftp' '--enable-sockets' '--enable-exif' '--with-pdflib=shared' '--with-mysql' 
make && make install 

Well after instillation of php4 and php5 we need to manage two httpd.conf files. In the default httpd.conf file we will activate php4 module and listing port of apache then in the second file we will active php5 module and listing port.

Lets first edit /etc/httpd/conf/httpd.conf file

/etc/httpd/conf/httpd.conf 

You need to add or modify these lines

LoadModule php4_module        /usr/lib/httpd/modules/libphp4.so
Listen 192.168.1.10:80 

Please change the listening ip address according to your network. Now we need to copy httpd.conf file into new name like (httpd-php5.conf) where we will defined php5 module and the listening port.

Just copy httpd.conf into httpd-php5.conf

cd /etc/httpd/conf/
cp httpd.conf httpd-php5.conf

Edit httpd-php5.conf file and modified these lines.

LoadModule php5_module        /usr/lib/httpd/modules/libphp5.so
Listen 192.168.1.10:81 

It is not possible to run multiple apache on same port that’s why we need bind php5 on port 81. But if you have multiple ip addresses on your system then you can run multiple instance of apache on port 80. In this case you only need to change ip address rather than port.

Now lets start the apache with two configurations.

/usr/sbin/httpd -f conf/httpd.conf
/usr/sbin/httpd -f conf/httpd-php5.conf 

I hope you will like this how-to.

10 comments

  1. Mardix says:

    So why do you wanna do that?

    C’mon guys, it’s time to let go of PHP 4. It doesn’t matter, update your codes or don’t use anything that is PHP 4.

    PHP5 Rocks! PHP6 on the way!

  2. Radical solution, to run two apache instances. Of course it will be more useful to run 5.2 and 5.3 along. :)
    There is a problem with the ‘–’ (double dash) in the cli commands as they are mangled in a unique long m-dash.

  3. [...] follow link to get more details on it. VN:R_U [1.7.8_1020]Rating: 0.0/10 (0 votes cast)VN:R_U [...]

  4. TomPier says:

    great post as usual!

  5. Valuable info. Lucky me I found your site by accident, I bookmarked it.

  6. cna classes says:

    It’s posts like this that keep me coming back and checking this site regularly, thanks for the info!

  7. I’ve recently started a blog, the information you provide on this site has helped me tremendously. Thank you for all of your time & work.

  8. Terrific work! This is the type of information that should be shared around the web. Shame on the search engines for not positioning this post higher!

  9. This is just what I needed, thanks a lot!

  10. There’s always something intersting to learn when reading your posts. All the best and I look forward to next time!

Leave a Reply

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

*