0% found this document useful (0 votes)
362 views

Install PHP 5.3 and 5.2 Together On Ubuntu 12.04

This document provides instructions for installing PHP 5.2 alongside PHP 5.3 on an Ubuntu 12.04 server to allow developing for both Drupal 6 and 7 simultaneously. It describes downloading PHP 5.2 source, configuring it with various options, and resolving common errors encountered during configuration such as missing dependencies. Installing required development packages is recommended to fix configuration errors. The document also lists commands to download PHP sources, configure, and compile the extension.

Uploaded by

braxanderz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
362 views

Install PHP 5.3 and 5.2 Together On Ubuntu 12.04

This document provides instructions for installing PHP 5.2 alongside PHP 5.3 on an Ubuntu 12.04 server to allow developing for both Drupal 6 and 7 simultaneously. It describes downloading PHP 5.2 source, configuring it with various options, and resolving common errors encountered during configuration such as missing dependencies. Installing required development packages is recommended to fix configuration errors. The document also lists commands to download PHP sources, configure, and compile the extension.

Uploaded by

braxanderz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Although Drupals 7+ run smoothly on PHP 5.3, Drupal 6 still feels much better with PHP 5.2.

Even
though D6 core is compatible with PHP 5.3 for quite some time now, a lot of contributes modules still
get nasty hiccup when asked to run on the newer version. Therefore developing for both D7 and D6 at
the same time becomes much less painful when running both versions of PHP in parallel.
One way of doing it is using mod_php5 Apache module to serve PHP 5.3 applications, while running
PHP 5.2 applications using fastcgi module. Under Ubuntu 12.04 this can be achieved by installing PHP
5.3 from the repositories and manually compiling and installing PHP 5.2 afterwards.
Installing PHP 5.3 from repositories is fairly easy process, which you most probably already have under
your belt, so let's just say that it looks more or less 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
What is much more interesting though, and what this post will focus on, is how to add PHP 5.2 to the
whole picture and make both those versions work nicely together.
Please note that this tutorial is for Apache's name-based virtual hosts, and essentially leaves PHP
5.3 enabled globally while allowing to use PHP 5.2 on specific, selected virtual hosts only.

Download PHP sources


Let's then start with downloading PHP 5.2 sources from Unsupported Historical Releaseslist.
I have originally started with version 5.2.10 (as it is the same version that we have on our production
servers), but then was stopped short by OpenSSL error during 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
to which I was not able to find any good fix (relatively easy to apply anyway), so finally ended up with
the most recent version from 5.2 branch - 5.2.17, where those errors haven't occured anymore.
Let's then download and uncompress PHP sources into ~/Downloads/php-5.2.17directory:

mkdir -p ~/Downloads/php-5.2.17
cd ~/Downloads/php-5.2.17
wget http://museum.php.net/php5/php-5.2.17.tar.gz
tar zxf php-5.2.17.tar.gz

Configure
Time to configure the package. Example ./configure call could look as follows:

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 need to adapt it to yur specific needs by adding and/or removing relevant options. You
can read more about options you want (or don't want) to include in PHP core configure
options documentation.

Configure errors
Now, that probably didn't work out of the box, did it?
In most cases quite a lot of dependencies will be missing. You can try to take care of them in one shot, if
you don't care too much about installing a little too much compared to what is really needed:

sudo apt-get install libxml2-dev libpcre3-dev libbz2-dev libcurl4openssl-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 remedy missing dependencies one by one, and install only those packages that are really
needed.
Let's go through some of the possible errors then (you can skip to the next section if
your ./configure finished without any errors and displayed nice Thank you for using PHP at the
end of its execution):
CONFIGURE: ERROR: XML2-CONFIG NOT FOUND. PLEASE CHECK
YOUR LIBXML2 INSTALLATION.
This error message suggests you don't have libxml2 installed. What it really means though is that you
don't have its development version installed!
Let's then search what we can find in available packages, what could help us resolve this issue:
$ 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
What we are interested in here is libxml2-dev, let's install it then:
sudo apt-get install libxml2-dev
The same procedure applies to all other missing libraries as well, so I will include only final install calls
from now on.
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
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 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 POSTGRESQL-SERVER-DEV-X.Y 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 PATH
sudo apt-get install postgresql-server-dev-9.1
Make sure you check result of apt-cache search especially in case of this error, as there could be
later version of PostgreSQL available.
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
/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 following switch to your ./configure options (optionally updating the path to reflect your
system):
--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 following switches to your ./configure options:
--with-pdo-sqlite=shared
--with-sqlite=shared

Make
Everything configured properly and without errors? Then it is time to compile (and go for a coffee while
it is running):

sudo make
Now sipping your coffee wait for approaching errors...

You might also like