📜 ⬆️ ⬇️

Simultaneous work of php 5.2 and php 5.3 on Ubuntu 12.04

image
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 working dev server.
Actually for developers under Drupal 6 and 7 and all who still use PHP 5.2.

Despite the fact that Drupal 7 works fine with PHP 5.3, Drupal 6 still feels much better with PHP 5.2. Although the D6 kernel has long been compatible with PHP 5.3, most developers get intolerable hiccups when they receive a request to upgrade a module to a new version. Therefore, the development for D7 and D6, it becomes more convenient with the simultaneous operation of both versions of PHP. (Note: this also incredibly simplifies the administration and maintenance of the dev servers by excluding the server from 5.2)

One way to solve this problem is to use mod_php5 for processing PHP 5.3 scripts, and using the FastCGI module when processing scripts for 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 repositories is a fairly simple operation that you most likely have already performed, so let's just decide that it looks 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

Notably, although this post focuses on how to install PHP 5.2, both versions work equally well.

PHP source code download

Let's start by downloading the source code from previous unsupported releases.

I originally started with version 5.2.10 (this version was installed on our stage servers) but was suddenly stopped by an OpenSSL error at the configuration stage.

/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


for which I could not find a working fix (relatively easily applicable), but the stage was completed with the latest version 5.2.17, giving out a bunch of other errors instead.

Well, download and unpack the sources in the folder ~ / Downloads / php-5.2.17

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

It's time to start configuring the package. Below is an example of calling the script ./configure:

./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

Obviously, you can tailor it to 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, is it? In most cases, the reason is missing dependencies. You can try to solve this problem with one shot, if you are not too worried about installing extra 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 missing dependency errors one by one, and install only those packages that are really needed.

Let's look at some of the possible errors (you can skip to the next section if the ./configure script ran without errors and a message is received
Thank you for using php


configure: error: xml2-config not found. Please check your libxml2 installation.

This error suggests that we check for the presence of the libxml2 package. In fact, this means that its dev version is missing.

Let's find available packages that can help solve this problem:
$ 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


We are interested in libxml2-dev , install it:
sudo apt-get install libxml2-dev

The same procedure applies to all missing libraries, so I will only give the final installation commands:

fixes
configure: error: Could not find pcre.h in / usr
sudo apt-get install libpcre3-dev

configure: error: Please reinstall the BZip2 distribution
sudo 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 the necessary header file (s).
checking for db4 major version ... configure: error: Header contains different version
sudo 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 a client-side application for building a client-side application.
configure: error: Cannot find libpq-fe.h. Please specify the correct PostgreSQL installation path
sudo apt-get install postgresql-server-dev-9.1

checking for FreeType 1 support ... no - FreeType 2.x is 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 / usr
sudo apt-get install libgd2-xpm-dev

configure: error: Unable to locate gmp.h
sudo 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.h
sudo 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 directory
sudo apt-get install freetds-dev

configure: error: Cannot find pspell
sudo 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 libtidy
sudo apt-get install libtidy-dev

configure: error: xslt-config not found. Please reinstall the libxslt> = 1.1.0 distribution
sudo 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 in the ./configure option:
--with-libdir = / lib / x86_64-linux-gnu

configure: error: You've configured extension pdo_sqlite to build it, but it depends on it. Pdo_sqlite shared or build pdo_sqlite
Add the following in the ./configure option
--with-pdo-sqlite=shared
--with-sqlite=shared



Make
Is everything set up correctly and without errors? Then it's time to compile (and a cup of coffee during its execution):

sudo make
Now you can while drinking coffee wait for the approach of errors.

Make errors

Yes, it is very likely that everything can go awry.
Here are two errors and one worning that you will most likely get:

fixes
ext / openssl / .libs / xp_ssl.o: In function `php_openssl_setup_crypto ':
ext / openssl / xp_ssl.c: 357: undefined reference to `SSLv2_server_method '
ext / openssl / xp_ssl.c: 337: undefined reference to `SSLv2_client_method '

This is related to 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:
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: In function 'zif_gmp_random':
ext / gmp / gmp.c: 1399: 69: error: '__GMP_BITS_PER_MP_LIMB' undeclared (first use in this function)
ext / gmp / gmp.c: 1399: 69: note: it appears

It's time to fix bug # 50990
In one of the comments on gmail dot com susan dot, the following working solution is proposed, which does the magic:

I solved the problem by replacing the outdated 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

The last bug is # 53568 that fixes pretty easily: open ext / zip / lib / zip_dirent.c and replace line 478:
memset(&tm, sizeof(tm), 0);
on
memset(&tm, 0, sizeof(tm));
No more mistakes!


Install
The simplest way to install your sleek 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 installing php? will also create a deb package in the current directory.
Now, no matter what path you choose, you have installed 5.2 MSR in / usr / bin / php52

Apache configuration files

The configuration directory / etc / php52 / apache2 / should already have been 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,

sudo ln -s /etc/php5/conf.d /etc/php52
sudo ln -s /etc/php5/cli /etc/php52


Copy the php.ini-recommended file to a 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 do is setting up apache to run PHP 5.2 using FastCGI. Start the installation of the fastcgi module:
sudo apt-get install libapache2-mod-fastcgi

Make sure all required modules are enabled and restart Apache:
sudo a2enmod cgi fastcgi actions
sudo service apache2 restart


Create a php52-cgi executable script to run the FastCGI version of PHP and put it in / usr / lib / cgi-bin /:
#!/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


PHPRC This parameter points to php.ini.
PHP_FCGI_CHILDREN number of threads
PHP_FCGI_MAX_REQUESTS query limit
You can learn more about this on the FastCGI website.

Give launch rights:
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 the use of PHP 5.2:
# Include file 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

FilesMatch overrides the php file handler.
ScriptAlias ​​hits the path to the CGI script
AddHandler registers new handler
Action activates the CGI script to work with files transferred from the handler.

Almost all!

Only one thing remains: 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 All the patches and comments please send to the PM. v

Source: https://habr.com/ru/post/176147/


All Articles