Installing php5.2 and php5.3 in parallel

_Running multiple versions of PHP at the same time is required if you are about running Druapl 5 and Druapl 6 or 7 together on the same server.

The following guide describes how to install php5.2 manually in parallel to php5.3, which includes compiling and installing php 5.2 from source.The instructions will work with the following Debian Linux versions and derived distributions: Debian sqeeze 6.0.4 and Ubuntu Precise Pangolin 12.04.

For similar instructions on installing php5.3 and php5.2 in parallel in older distributions please refer to Install php5.3 to php5.2 in parallel in ubuntu-11.10._

see also:

Install additional packages

apt-get install bison re2c libmysqlclient-dev libbz2-dev bzip2 libxslt1.1 libxslt1-dev libxml2 libxml2-dev libjpeg62-dev libpng12-dev libxpm-dev dpkg-dev libcurl4-gnutls-dev gawk libgd2-xpm-dev libgd2-xpm libmhash-dev

You may need more package if you are not having apache2, mysql, gcc and linux sources.

Check symlinks in /usr/lib

Check if the below symbolic links exist if nor create them!:

Ubuntu and Debian:

ln -s /usr/include/gd.h /usr/lib/gd.h

Ubuntu only:

cd /usr/lib
ln -s x86_64-linux-gnu/libjpeg.a libjpeg.a
ln -s x86_64-linux-gnu/
ln -s x86_64-linux-gnu/libpng.a libpng.a
ln -s x86_64-linux-gnu/
ln -s x86_64-linux-gnu/
ln -s x86_64-linux-gnu/libgd.a libgd.a
ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib/

see also

Download and extract php 5.2 source

  1. download

  2. extract

  3. cd into the extracted folder

Run the configure command

_This configuration is based on based on pkg-php/php.git/debian/rules":;a=blob_plain;f=debian/rules;hb=HEAD._ The php5.2 rules are found "here

Run the configure command below inside the extracted php source folder.

dpkg-architecture -qDEB_HOST_GNU_TYPE

./configure is reporting errors:

  1. I you are getting an error like configure: error: xxxx not found. Please check your XXXX installation. Check if you have installed the xxx package and also the according development package.

  2. You can debug your the configuration by searching for the line of code in ./configure wich is producing the error message and add the following code snipped before the lines found:

set -x

Execute the configure command again an see the detailed output.

Build and install

# optional, dauert, findet aber Fehler:
make test
# bringt die Dateien an ihren Platz: 
sudo make install | tee php52-install.log

Configure Apache

This was the tricky part!

Now please follow the instruction on:

The instruction on this page are on manually installing php 5.3, so you have to replace all occurrences of "php53" by "php52" in order translate it to our case.

Since the original blog post is no longer available I am copying the relevant paragraphs to here:

original blog post from Bernhard Häussner -

Jetzt muss noch Apache über das neue CGI-Modul informiert werden. Dazu müssen die folgenden Konfigurationen gesetzt werden (z.B. elegant in einer neuen Datei /etc/apache2/conf.d/php52cgi.conf):

# Installed manually
# based on
# see also

AddHandler php52-cgi .php52

ScriptAlias /bin-php52 /usr/bin/php52/

Action php52-cgi /bin-php52/php-cgi

# configuring the php52 binaries folder
<Directory /usr/bin/php52>
    # NO .htaccess:
    AllowOverride None
    Options +ExecCGI +FollowSymLinks
    # normalerweise ist der Zugriff auf alle „sonstigen“ Dateien gesperrt, 
    # daher hier wieder freigeben: 
    Order allow,deny
    Allow from all

Zum Testen kann man z.B. eine phpinfo.php52-Datei anlegen und man sollte die neue PHP-Verion angezeigt bekommen. Auf dieser Info-Seite kann man dann prüfen, ob alle Module verwendbar sind, die Zeitzone gesetzt ist und anderen potentielle Konfigurationsfehler auf die Schliche kommen. PHP 5.2 wird auch seine eigene php.ini in /etc/php53/apache2/php.ini verwenden, wohin man vielleicht zunächst die alte Konfigurationsdatei kopieren will.

# php.ini replazieren:
sudo cp /etc/php5/apache2/php.ini /etc/php53/apache2/php.ini
# im Webroot phpinfo mit namespace-Spielerei anlegen :)
echo "<?php namespace YEEES; phpinfo();" > phpinfo.php53

Nach den Schritten dieses Tutorials dürfte dann PHP 5.2 mehr oder weniger optimal laufen, ohne dass die Funktion alter Scripte eingeschränkt werden muss, und es lässt sich einfach die Interkompatibilität zwischen den Versionen testen.

Virtual Host and directory configuration

In your virtual host configuration file, put a SetHandler directive in the according Directory directive. E.g:

# Drupal 5 to run with php5.2
<Directory /var/www/drupal5>
    # run Drupal 5 with php5.2 which has been installed manually
    # see also

    <FilesMatch "\.php">
        SetHandler php52-cgi
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all

Updated by Andreas Kohlbecker over 9 years ago · 38 revisions