
Running php 5.2 and php 5.3 at the same time on Ubuntu 12.04
- Transfer
- Tutorial

I was looking for a solution to this problem, since keeping an outdated version of ubuntu 10.04 on a separate server seemed unnecessary. Installation time ~ 1 hour. Installation was performed on a running dev server.
Actual for developers under Drupal 6 and 7 and all who still use PHP 5.2.
Despite the fact that Drupal 7 runs fine on PHP 5.3, Drupal 6 still feels much better with PHP 5.2. Although the D6 core has long been compatible with PHP 5.3, most developers have unbearable hiccups when they receive a request to update the module to a new version. Therefore, development for D7 and D6 becomes more convenient when both versions of PHP work simultaneously. (note also it incredibly simplifies administration and maintenance of dev servers by excluding the server from 5.2)
One way to solve this problem is to use mod_php5 to process PHP 5.3 scripts, and use the FastCGI module if necessary to process scripts under PHP 5.2. Accordingly, for Ubuntu 12.04, you can install PHP 5.3 from the repository and then manually compile and install PHP 5.2. Installing PHP 5.3 from the repositories is a fairly simple operation that you most likely have already performed, so let's just decide it looks something like this:
sudo apt-get install php5 php5-common php5-cli php5-dev php5-mysql phpmyadmin php5-pgsql phppgadmin php5-gd php5-mcrypt php5-curl php-pear libapache2-mod-php5 php5-xdebug php5-codesniffer
Remarkably, although this post focuses on how to install PHP 5.2, both versions work equally well.
Downloading PHP Source Code
Let's start by downloading the source code from previous unsupported releases.
I initially started with version 5.2.10 (this version was installed on our stage servers) but was suddenly stopped by the OpenSSL error at the configuration stage. for which I could not find a working fix (relatively easy to apply), but the stage was completed with the latest version 5.2.17, giving instead a bunch of other errors. Well, download and unzip the sources into the folder ~ / Downloads / php-5.2.17 Configure It's time to start configuring the package. The following is an example script call ./configure:
/usr/include/openssl/conf.h:132:7: note: expected 'struct lhash_st_CONF_VALUE *' but argument is of type 'int *'
make: *** [ext/openssl/openssl.lo] Error 1
mkdir -p ~/Downloads/php-5.2.17
cd ~/Downloads/php-5.2.17
wget museum.php.net/php5/php-5.2.17.tar.gz
tar zxf php-5.2.17.tar.gz
./configure
sudo ./configure \
--prefix = / usr / share / php52 \
--datadir = / usr / share / php52 \
--mandir = / usr / share / man \
--bindir = / usr / bin / php52 \
- -with-libdir = lib64 \
--includedir = / usr / include \
--sysconfdir = / etc / php52 / apache2 \
--with-config-file-path = / etc / php52 / cli \
--with-config- file-scan-dir = / etc / php52 / conf.d \
--localstatedir = / var \
--disable-debug \
--with-regex = php \
--disable-rpath \
--disable-static \
- disable-posix \
--with-pic \
--with-layout = GNU \
--with-pear = / usr / share / php \
--enable-calendar \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg \
--enable-bcmath \
--with-bz2 \
--enable-ctype \
--with-db4 \
--without-gdbm \
--with-iconv \
--enable-exif \
- enable-ftp \
--enable-cli \
--with-gettext \
--enable-mbstring \
--with-pcre-regex = / usr \
--enable-shmop \
--enable-sockets \
--enable-wddx \
--with-libxml-dir = / usr \
--with-zlib \
--with-kerberos = / usr \
--with-openssl = / usr \
--enable-soap \
--enable-zip \
- with-mhash \
--with-exec-dir = / usr / lib / php5 / libexec \
--without-mm \
--with-curl = shared, / usr \
--with-zlib-dir = / usr \
--with-gd = shared, / usr \
--enable-gd-native-ttf \
--with-gmp = shared, / usr \
--with-jpeg-dir = shared, / usr \
--with-xpm-dir = shared, / usr / X11R6 \
--with-png-dir = shared, / usr \
--with-freetype-dir = shared, / usr \
--with -ttf = shared, / usr \
--with-t1lib = shared, / usr \
--with-ldap = shared, / usr \
--with-mysql = shared, / usr \
--with-mysqli = shared, / usr / bin / mysql_config \
--with-pgsql = shared, / usr \
--with-pspell = shared, / usr \
--with-unixODBC = shared, / usr \
--with-xsl = shared, / usr \
--with-snmp = shared, / usr \
--with-sqlite = shared, / usr \
--with-tidy = shared, / usr \
--with-xmlrpc = shared \
--enable-pdo = shared \
--without-pdo-dblib \
--with-pdo-mysql = shared, / usr \
--with-pdo-pgsql = shared, / usr \
--with-pdo-odbc = shared, unixODBC, / usr \
--with-pdo-dblib = shared, / usr \
--enable-force-cgi-redirect --enable-fastcgi \
--with-libdir = / lib / x86_64-linux-gnu \
--with-pdo-sqlite = shared \
--with-sqlite = shared \
--enable-ipv6 \
--with-mcrypt \
--with-imap-ssl
--prefix = / usr / share / php52 \
--datadir = / usr / share / php52 \
--mandir = / usr / share / man \
--bindir = / usr / bin / php52 \
- -with-libdir = lib64 \
--includedir = / usr / include \
--sysconfdir = / etc / php52 / apache2 \
--with-config-file-path = / etc / php52 / cli \
--with-config- file-scan-dir = / etc / php52 / conf.d \
--localstatedir = / var \
--disable-debug \
--with-regex = php \
--disable-rpath \
--disable-static \
- disable-posix \
--with-pic \
--with-layout = GNU \
--with-pear = / usr / share / php \
--enable-calendar \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg \
--enable-bcmath \
--with-bz2 \
--enable-ctype \
--with-db4 \
--without-gdbm \
--with-iconv \
--enable-exif \
- enable-ftp \
--enable-cli \
--with-gettext \
--enable-mbstring \
--with-pcre-regex = / usr \
--enable-shmop \
--enable-sockets \
--enable-wddx \
--with-libxml-dir = / usr \
--with-zlib \
--with-kerberos = / usr \
--with-openssl = / usr \
--enable-soap \
--enable-zip \
- with-mhash \
--with-exec-dir = / usr / lib / php5 / libexec \
--without-mm \
--with-curl = shared, / usr \
--with-zlib-dir = / usr \
--with-gd = shared, / usr \
--enable-gd-native-ttf \
--with-gmp = shared, / usr \
--with-jpeg-dir = shared, / usr \
--with-xpm-dir = shared, / usr / X11R6 \
--with-png-dir = shared, / usr \
--with-freetype-dir = shared, / usr \
--with -ttf = shared, / usr \
--with-t1lib = shared, / usr \
--with-ldap = shared, / usr \
--with-mysql = shared, / usr \
--with-mysqli = shared, / usr / bin / mysql_config \
--with-pgsql = shared, / usr \
--with-pspell = shared, / usr \
--with-unixODBC = shared, / usr \
--with-xsl = shared, / usr \
--with-snmp = shared, / usr \
--with-sqlite = shared, / usr \
--with-tidy = shared, / usr \
--with-xmlrpc = shared \
--enable-pdo = shared \
--without-pdo-dblib \
--with-pdo-mysql = shared, / usr \
--with-pdo-pgsql = shared, / usr \
--with-pdo-odbc = shared, unixODBC, / usr \
--with-pdo-dblib = shared, / usr \
--enable-force-cgi-redirect --enable-fastcgi \
--with-libdir = / lib / x86_64-linux-gnu \
--with-pdo-sqlite = shared \
--with-sqlite = shared \
--enable-ipv6 \
--with-mcrypt \
--with-imap-ssl
Obviously, you can adapt it to your specific needs by adding and / or removing the appropriate options. You can learn more about the options you need (or don't need) in the documentation for PHP.
./Configure errors
So this probably doesn't work out of the box, right? In most cases, the cause is missing dependencies. You can try to solve this problem with one shot, if you are not too worried about installing unnecessary libraries and packages:
sudo apt-get install libxml2-dev libpcre3-dev libbz2-dev libcurl4-openssl-dev libdb4.8-dev libjpeg-dev libpng12-dev libxpm-dev libfreetype6-dev libmysqlclient-dev postgresql-server-dev-9.1 libt1-dev libgd2-xpm-dev libgmp-dev libsasl2-dev libmhash-dev unixodbc-dev freetds-dev libpspell-dev libsnmp-dev libtidy-dev libxslt1-dev libmcrypt-dev
You can also fix errors of missing dependencies one after another, and install only those packages that are really needed.
Let's look at some of the possible errors, (you can go to the next section if the ./configure script is executed without errors and a message is received
Thank you for using PHP at the end of its execution
configure: error: xml2-config not found. Please check your libxml2 installation.
This error prompts us to check for the presence of the libxml2 package. In reality, this means that its dev version is missing.
Let's find available packages that can help solve this problem: We are interested in libxml2-dev , install it: The same procedure applies to all missing libraries, so I will give only the final installation commands:
$ apt-cache search libxml2 | grep dev
libcroco3-dev - Cascading Style Sheet (CSS) parsing and manipulation toolkit
libxml++2.6-dev - C++ interface to the GNOME XML library (libxml2)
libxml2-dev - Development files for the GNOME XML library
libgdome2-cpp-smart-dev - C++ bindings for GDome2 DOM implementation
libgdome2-dev - Development files for libgdome2
libgdome2-ocaml-dev - OCaml bindings for GDome2 DOM implementation
libgtkmathview-dev - rendering engine for MathML documents
libsp-gxmlcpp-dev - S+P C++ wrapper for Gnome libxml2/libxslt
sudo apt-get install libxml2-dev
fixes
configure: error: Could not find pcre.h in / usrsudo apt-get install libpcre3-dev
configure: error: Please reinstall the BZip2 distributionsudo apt-get install libbz2-dev
configure: error: Please reinstall the libcurl distribution - easy.h should be in / include / curl /sudo apt-get install libcurl4-openssl-dev
configure: error: DBA: Could not find necessary header file (s).
checking for db4 major version ... configure: error: Header contains different versionsudo apt-get install libdb4.8-dev
configure: error: libjpeg. (a | so) not found.sudo apt-get install libjpeg-dev
configure: error: libpng. (a | so) not found.sudo apt-get install libpng12-dev
configure: error: libXpm. (a | so) not found.sudo apt-get install libxpm-dev
configure: error: freetype.h not found.sudo apt-get install libfreetype6-dev
You need to install postgresql-server-dev-XY for building a server-side extension or libpq-dev for building a client-side application.
configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation pathsudo apt-get install postgresql-server-dev-9.1
checking for FreeType 1 support ... no - FreeType 2.x is to be used instead
configure: error: Your t1lib distribution is not installed correctly. Please reinstall it.sudo apt-get install libt1-dev
configure: error: Unable to find gd.h anywhere under / usrsudo apt-get install libgd2-xpm-dev
configure: error: Unable to locate gmp.hsudo apt-get install libgmp-dev
configure: error: Cannot find MySQL header files under / usr.
Note that the MySQL client library is not bundled anymore!sudo apt-get install libmysqlclient-dev
configure: error: sasl.h not found!sudo apt-get install libsasl2-dev
configure: error: Please reinstall libmhash - I cannot find mhash.hsudo apt-get install libmhash-dev
checking for unixODBC support ... configure: error: ODBC header file '/usr/include/sqlext.h' not found!sudo apt-get install unixodbc-dev
configure: error: Directory / usr is not a FreeTDS installation directorysudo apt-get install freetds-dev
configure: error: Cannot find pspellsudo apt-get install libpspell-dev
configure: error: SNMP sanity check failed. Please check config.log for more information.sudo apt-get install libsnmp-dev
configure: error: Cannot find libtidysudo apt-get install libtidy-dev
configure: error: xslt-config not found. Please reinstall the libxslt> = 1.1.0 distributionsudo apt-get install libxslt1-dev
configure: error: mcrypt.h not found. Please reinstall libmcrypt.sudo apt-get install libmcrypt-dev
configure: error: Cannot find OpenSSL's libraries
Add the following to the ./configure options:
--with-libdir = / lib / x86_64-linux-gnu
configure: error: You've configured extension pdo_sqlite to build statically, but it depends on extension pdo, which you've configured to build shared. You either need to build pdo_sqlite shared or build pdo statically for the build to be successful.
Add the following to the options ./configure--with-pdo-sqlite=shared
--with-sqlite=shared
Make
Everything configured correctly and without errors? Then the time came to compile (and a cup of coffee during its execution):
sudo make
Now you can, while drinking coffee, wait for errors to approach.
Errors make
Yes, it is very likely that everything can go awry here.
Here are two errors and one vorning that you most likely will receive:
fixes
the ext / the openssl / .libs / xp_ssl.o: with In function `php_openssl_setup_crypto ':
the ext / the openssl / xp_ssl.c: 357: the reference to` undefined The SSLv2_server_method'
the ext / the openssl / xp_ssl.c: 337: undefined reference to `SSLv2_client_method '
It connected with bug # 54736 which are easily solved by applying the patch attached to this bug report
Download this patch to the ~ / Downloads / php-5.2.17 folder and do the following:patch -p1 < debian_patches_disable_SSLv2_for_openssl_1_0_0.patch.patch
You should see a message about the successful application of the patch, like this: ext / gmp / gmp. c: In function 'zif_gmp_random': ext / gmp / gmp.c: 1399: 69: error: '__GMP_BITS_PER_MP_LIMB' undeclared (first use in this function)patching file ext/openssl/xp_ssl.c
Hunk #1 succeeded at 332 (offset 4 lines).
Hunk #2 succeeded at 354 (offset 4 lines).
Hunk #3 succeeded at 583 (offset -50 lines).
Hunk #4 succeeded at 819 (offset -98 lines).
ext / gmp / gmp.c: 1399: 69: note: each undeclared identifier is reported only once for each function it appears in
Time to fix the bug # 50990
In one of the comments susan dot smith dot dev at gmail dot com the following working solution is offered that does magic:I solved the problem by replacing the deprecated constant definition __GMP_BITS_PER_MP_LIMB with GMP_LIMB_BITS , which is present in all previous versions and MPIR defines too.
You need to edit the ext / gmp / gmp.c file and replace __GMP_BITS_PER_MP_LIMB with GMP_LIMB_BITS. In my case, it was line 1399.
ext / zip / lib / .libs / zip_dirent.o: In function `memset ':
/usr/include/x86_64-linux-gnu/bits/string3.h:82: warning: memset used with constant zero length parameter; this could be due to transposed parameters
Last bug # 53568 which is pretty easy to fix: open the file ext / zip / lib / zip_dirent.c and replace the line 478:memset(&tm, sizeof(tm), 0);
atmemset(&tm, 0, sizeof(tm));
more bugs there!
Install
The simplest installation option for your shiny new version of PHP 5.2 is the following command:
sudo make install
In addition, if you plan to repeat the same installation again on other machines, or just want to save the installation package file for the future, you can run:
sudo checkinstall
which along with the PHP installation? will also create a deb package in the current directory.
Now, no matter which path you choose, you have installed ЗЗЗ 5.2 in / usr / bin / php52
Apache configuration files The
configuration directory / etc / php52 / apache2 / should already be created during the installation process (create it if it is missing). Now you need to configure PHP 5.2 to use the same extensions and modules that PHP 5.3 uses. Copy the file
sudo ln -s /etc/php5/conf.d /etc/php52
sudo ln -s /etc/php5/cli /etc/php52
php.ini-recommended to the new directory (which will be defined in the next step)
sudo cp php.ini-recommended /etc/php52/apache2/php.ini
and, if necessary, make the necessary settings.
Apache and FastCGI
The next thing we will do is configure apache to run PHP 5.2 using FastCGI. Let's start the installation of the fastcgi module:
sudo apt-get install libapache2-mod-fastcgi
Make sure that all required modules are enabled and restart Apache: Create the php52-cgi executable script to run the FastCGI version of PHP and put it in / usr / lib / cgi-bin /: PHPRC this parameter points to php.ini PHP_FCGI_CHILDREN number of threads PHP_FCGI_MAX_REQUESTS limit of requests You can learn more about this on the FastCGI website
sudo a2enmod cgi fastcgi actions
sudo service apache2 restart
#!/bin/sh
PHPRC="/etc/php52/apache2/"
export PHPRC
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec /usr/bin/php52/php-cgi
.
Give permission to run:
sudo chmod +x /usr/lib/cgi-bin/php52-cgi
Finally, create a new /etc/apache2/php52.conf file that will be used for virtual hosts that require PHP 5.2: ScriptAlias / php52-cgi / usr / lib / cgi-bin / php52-cgi Action application / x-httpd-php5 / php52-cgi AddHandler application / x-httpd-php5 .php FilesMatch overrides the php file handler. ScriptAlias sets the path to the CGI script. AddHandler registers a new handler. Action activates a CGI script to work with files transferred from the handler. Almost all!
# Include file for virtual hosts that need to run PHP 5.2
SetHandler application/x-httpd-php5
There is only one thing left: for all hosts for which you want to use PHP 5.2 you need to add the following line to the configuration file:
Include php52.conf
and reload the new configuration:
sudo service apache2 reload
Congratulations! Now you have a server with simultaneously running versions of PHP 5.2 and PHP 5.3!
PS I ask to send all typos and comments to PM. v