Monthly Archives: February 2014
Multiple php versions on Centos
Hi , you may come across situations to have multiple php versions installed on a server. Here I will explain a simple method to accomplish this. Lets take php versions 5.2 and 5.4 and I am going to install it in different locations than default installation directory.
Note for 2 versions of php one version should be compiled as fcgi.
1. Install php 5.2:
a. Download php tar file from “http://php.net/downloads.php”
Here I am going to compile this php as fastcgi and using custom installation directory /opt/php52. Configure command is given below.
==========
# ./configure –prefix=/opt/php52 –with-config-file-path=/opt/php52 –with-curl –enable-cli –enable-fastcgi –enable-discard-path –enable-force-cgi-redirect –with-mysql –with-mysqli –enable-bcmath –enable-ftp –enable-magic-quotes –with-pear –enable-sockets –with-zlib –with-gd –with-jpeg-dir=/usr/lib –with-libdir=lib64 –with-bz2 –enable-calendar –with-curl –enable-dbase –enable-exif –with-gettext –with-gmp –enable-mbstring –with-mcrypt –with-mhash –with-ncurses=shared –with-openssl –enable-pcntl –with-pdo-mysql –with-pspell –with-readline –enable-shmop –with-snmp=shared –enable-sysvsem –enable-sysvshm –enable-sysvmsg –enable-wddx –with-kerberos –with-imap-ssl –enable-zip –with-xsl –with-tidy –enable-soap
# make && make install
============
If you got error while executing ‘make’ command like “Compile: /usr/bin/ld: cannot find -lltdl, collect2: ld returned 1 exit status” please install libtool using following command.
yum install libtool-ltdl-devel
Copy php.ini-recommended from the install directory to /opt/php52/
2. Install php 5.4
This one also going to install in separate location say /opt/php54
===========
#./configure –prefix=/opt/php54 –with-config-file-path=/opt/php54 –with-curl –enable-cli –enable-discard-path –with-mysql –with-mysqli –enable-bcmath –enable-ftp –enable-magic-quotes –with-pear –enable-sockets –with-zlib –with-gd –with-jpeg-dir=/usr/lib –with-libdir=lib64 –with-bz2 –enable-calendar –with-curl –enable-dbase –enable-exif –with-gettext –with-gmp –enable-mbstring –with-mcrypt –with-mhash –with-ncurses=shared –with-openssl –enable-pcntl –with-pdo-mysql –with-pspell –with-readline –enable-shmop –with-snmp=shared –enable-sysvsem –enable-sysvshm –enable-sysvmsg –enable-wddx –with-kerberos –with-imap-ssl –enable-zip –with-xsl –with-tidy –enable-soap
# make && make install
===========
Copy php.ini-production from install directory to /opt/php54.
Now in apache configuration file include following line or uncomment it.
Include conf/extra/httpd-fastcgi.conf
Now create this file “/usr/local/apache/conf/extra/httpd-fastcgi.conf” and add below contents to it.
==========
LoadModule fastcgi_module modules/mod_fastcgi.so
FastCgiIpcDir /opt/tmp/fcgi
AddHandler fastcgi-script .fcgi
FastCgiConfig -autoUpdate -singleThreshold 200 -killInterval 600 -idle-timeout 150
AddType application/x-httpd-php .php
ScriptAlias /fastcgi/ /usr/local/apache/cgi-bin/
<Directory “/usr/local/apache/cgi-bin”>
Options ExecCGI
SetHandler fastcgi-script
Order allow,deny
Allow from all
</Directory>
==========
Make sure that “mod_fastcgi.so” exists in the modules directory. Now create a directory “/opt/tmp/fcgi” and give 777 permission.
Navigate to directory “/usr/local/apache/cgi-bin/”.
a. Create a file for php 5.2 say “php52.fcgi” with 755 or executable permission and add following contents to it. Make sure you have added correct path for php-cgi binary.
==========
#!/bin/sh
PHP_FCGI_CHILDREN=8
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec /opt/php52/bin/php-cgi
==========
Similarly create a file for php 5.4 say php54.cgi with following contents.
==========
#!/bin/sh
PHP_FCGI_CHILDREN=8
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec /opt/php54/bin/php-cgi
==========
Finally go to virtual host section of each domain and specify which php to use for the domain. Imagine I have to use php 5.2 for a domain called abc.com. Go to virtual host of domain abc.com and add following line to it.
==========
Action application/x-httpd-php /fastcgi/php52.fcgi
==========
For domains using php version 5.4 add following line.
==========
Action application/x-httpd-php /fastcgi/php54.fcgi
==========
Finally restart apache service. Thats it. Put a php info page and check php versions displaying.
Thanks,
Jeen