php5.2 on Ubuntu 10.04 LTS

Can anyone give me some advice as to how to have php5.2 installed parallel to php5.3 and running on certain domains?


Unfortunately, there isn’t an easy way to do this.

There are some hard ways, but they’re, well, pretty hard :slight_smile:

You’d need to manually compile a PHP version (or create your own set of .deb’s), install it into a custom location, and then in $HOME/cgi-bin (or fcgi-bin), edit the php5.cgi file for the domain that should be using the other version, and change the PHP path.

And then from there, you have to take care to keep your custom PHP version up to date, or you could end up with security issues.

I’d personally suggest not trying to install two PHP versions side-by-side, but if it’s really something you’d want, it should work :slight_smile:


I have compiled and created a new php5.2, which is located in /opt/php-5.2.17/bin. I am just not sure how to get this to work properly - I have tried putting a cgi version into the correct places, however, it does not work correctly!

What you’d need to do is edit the php5.cgi file in the domain’s cgi-bin or fcgi-bin directory, and change the path of “/usr/bin/php5-cgi” at the end of the file to point to your new PHP binary.

If that doesn’t work, let us know what error(s) you get. Be sure to take a look in $HOME/logs/error_log for any errors.


That may mean that your website isn’t executing that particular script. Make sure that your website is configured to use CGI or fcgid, using mod_php wouldn’t work for what you need. You can configure all that within Server Configuration -> Website Options -> PHP Execution Mode.


I have managed to get it working at last

I will write up a howto - but before I do, what are the escapes to put code into this forum?

What I did discover is that one has to disable mod_php site-wide, and then run php5.2 as CGI, not FCGI, then edit the /home/sitename/cgi.bin/php5.cgi file after chattr -i php5.cgi

Thanks for the pointers

To quickly insert code into a text line, enclose it in backticks ("\`")

For multi-line code blocks, use the tags \[code\]...codeblock...\[/code\].

I needed to run 1 site on my Ubuntu 10.04 LTS server running under php5.2. I did not want to downgrade my entire server to run php5.3. This is how to go about it:

Compile and install php5.2 on the server in an alternate location.

Log in to the server as a regular user

Download the source:


Extract the tarball:

tar -jxf php-5.2.17.tar.bz2
cd php-5.2.17

You will also probably need to install some development libraries, the ones I required are listed below:

sudo apt-get install libxml2-dev
sudo apt-get install libcurl4-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libmysqlclient-dev
sudo apt-get install libltdl-dev
sudo apt-get install libpng-dev
sudo apt-get install libmcrypt-dev
sudo apt-get install libpq-dev

Run configure:

./configure --prefix=/opt/php-5.2.17 --with-config-file-path=/usr/local/php-5.2 
--with-mcrypt --with-pgsql --with-mysqli --with-mysql --with-curl --with-gd --wi
th-jpeg-dir --enable-cli --enable-fastcgi --enable-discard-path --enable-force-c
gi-redirect --with-zlib

This may also complain about other libraries not installed - install any of those it complains about and re-run configure after installing each one it complains about until configure runs cleanly.

Now make and install:

make test
sudo make install

The resulting php build will be located in /opt/php-5.2.17

Copy the php.ini file to the correct location

sudo cp php.ini-recommended /usr/local/php5.2/php.ini

Ensure that apache2 is not running with mod_php

sudo a2dismod php5

From the Virtualmin web interface locate the virtual server to run php5.2 and change it to run in CGI mode using Server Configuration -> Website Options -> PHP script execution mode

Edit the php5.cgi file located in the cgi-bin directory of the virtual server so the last line reads:

exec /opt/php-5.2.17/bin/php-cgi

NOTE: Under Virtualmin, the above file has the immutable attribute set, so prior to editing the file, issue the command: sudo chattr -i pgp5.cgi and after editing the file sudo chattr +i php5.cgi

Now restart Apache

sudo /etc/init.d/apache2 restart

Hi, been away for a while. Getting back to this issue, I have edited the php5.cgi file for the domain and it is now as follows:

export PHPRC
umask 022
exec /opt/php-5.2.17/bin/php-cgi

I have added a phpinfo.php script to the public_html directory for that domain. When I call up that file in a browser, the phpinfo shows the php info of the Ubuntu installation of php5.3

From a shell if run /opt/php-5.2.17/bin/php phpinfo.php I get the php5.2 info.

The above php5.cgi is the only configuration file I have changed.


I’m very interested that users could change their PHP versions by themselves through .htaccess file. What is the easyiest way if server is set up by following this tutorial? Can it be done without rebooting Apache?
Thank you.

So nobody knows how to switch between PHP with .htaccess? I have tried various ways and combinations but none of them was successful. I notice that most hosting companies offer to insert to .htaccess file lines like these:

To switch to PHP 5.0: AddHandler application/x-httpd-php5 .php .php5 .php4 .php3 To switch to PHP 5.1: AddHandler application/x-httpd-php51 .php .php5 .php4 .php3 ..... ..... As I understood this method is only valid if I will use CGI mode. For FCGI it is not valid. What files should be changed if we want to activate specific PHP version through .htaccess? Any help will be very appriciated.


me too! looking all over, only wha ti can find is for virtualhosts and that doesnt work in the .htaccess (FileMatch throws errors and nothing without it(

did you find a solution?

No, I still missing a solutions. Every time I change path to necessary php version in php5.cgi file by myself. It’s not convienent. A lot of hosting companies offer such functionality through .htaccess. I don’t understand why is that not working in Virtualmin environment… Does anybody find a solution?

Use PHPFARM from GIT. Very simple install and you can run diferent PHP over CGI.

How about this

and this one

At the recheck config step though Virtualmin is not recognizing my second php…