Wednesday, July 6, 2011

15 steps for running PHP 5.3 and PHP 5.2 on the same Apache server

Recently i faced with a case when i need to run an old website which requires PHP 5.2 when my main version on the test server is 5.3.5

System configuration:
Debian Squeeze 6.0
Apache 2.2
MySQL 5.1

Here i place a very short step by step instruction for how to do so.

1. Go to and download needed php version.

2. Extract just downloaded file: shell> tar xzvf php-5.2.17.tar.gz

3. Install PHP development libraries:
as root:
shell> apt-get update
shell> apt-get install libxml2-dev libmysqlclient-dev libcurl4-gnutls-dev libcurl4-openssl-dev libpng12-dev libjpeg62-dev

4. go to the folder where you extracted PHP archive

5. configure and make it:
shell> ./configure --prefix=/opt/php5.2 \
--with-config-file-path=/opt/php5.2 \
--with-mysqli \
--with-pdo-mysql \
--with-mysql \
--with-curl \
--with-gd \
--with-jpeg \
--with-jpeg-dir \
--with-xsl \
--with-zlib \
--enable-cli \
--enable-fastcgi \
--enable-discard-path \
shell> make
shell> make install

6. Install and set up fastcgi support for PHP:
shell> apt-get install libapache2-mod-fastcgi

7. Enable fastcgi:
shell> a2enmod fastcgi

8. Enable mod_actions:
shell> a2enmod actions

9. Set up PHP cgi wrapper. Create file '/usr/lib/cgi-bin/php52-cgi' with the following content:
export PHPRC
exec /opt/php5.2/bin/php-cgi
10. Make this file executable:
shell> chmod +x /usr/lib/cgi-bin/php5-cgi

11. Create include file for Virtual Hosts: '/etc/apache2/php52.conf'

12. Fill it in with the following content:
#include for virtual hosts that need to run php-5.2
<FilesMatch "\.php">
   SetHandler application/x-httpd-php5
ScriptAlias /php52-cgi /usr/lib/cgi-bin/php52-cgi
Action application/x-httpd-php5 /php52-cgi
AddHandler application/x-httpd-php5 .php
13. copy php.ini-recommended file to /opt/php5.2/ and rename it to php.ini

14. Include this file in to Virtual Hosts, where PHP2 is needed.
<VirtualHost *.80>

# ...

#needs to run version 5.2.x of PHP
Include php52.conf


15. Restart Apache: /etc/init.d/apache2 restart

That is it.

Thanks to Brett's blog!

Also I invite you to visit us at