Installing multiple versions of PHP on CentOS 6

I will install the latest version of PHP 5.3 and a 5.4

Install PHP-FPM and FastCGI. We compile them both once fpm then cgi.

Let’s proceed to the installation of two versions of php

First we disable selinux. It is not mandatory but do not confuse. Complete the installation and then if you want redo SELinux.

nano /etc/sysconfig/selinux

(replace enforcing cu disabled)

SELINUX=disabled

We have to create the directory for extraction, install and download php-5.3.9.

mkdir /usr/local/src/php5-build
cd /usr/local/src/php5-build
wget http://museum.php.net/php5/php-5.3.9.tar.bz2
tar jxf php-5.3.9.tar.bz2
cd php-5.3.9
yum groupinstall 'Development Tools'

Install everything we need (command is long)

yum install libxml2-devel libXpm-devel gmp-devel libicu-devel t1lib-devel aspell-devel openssl-devel bzip2-devel libcurl-devel libjpeg-devel libvpx-devel libpng-devel freetype-devel readline-devel libtidy-devel libxslt-devel libmcrypt-devel pcre-devel curl-devel mysql-devel ncurses-devel gettext-devel net-snmp-devel libevent-devel libtool-ltdl-devel libc-client-devel postgresql-devel

 

rpm -ivh http://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install -y php-mcrypt
reboot

Configure PHP 5.3.9

cd /usr/local/src/php5-build/php-5.3.9
mkdir /opt/phpfcgi-5.3.9
./configure \
 --prefix=/opt/phpfcgi-5.3.9 \
 --with-pdo-pgsql \
 --with-zlib-dir \
 --with-freetype-dir \
 --enable-mbstring \
 --with-libxml-dir=/usr \
 --enable-soap \
 --enable-calendar \
 --with-curl \
 --with-mcrypt \
 --with-zlib \
 --with-gd \
 --with-pgsql \
 --disable-rpath \
 --enable-inline-optimization \
 --with-bz2 \
 --with-zlib \
 --enable-sockets \
 --enable-sysvsem \
 --enable-sysvshm \
 --enable-pcntl \
 --enable-mbregex \
 --with-mhash \
 --enable-zip \
 --with-pcre-regex \
 --with-mysql \
 --with-pdo-mysql \
 --with-mysqli \
 --with-jpeg-dir=/usr \
 --with-png-dir=/usr \
 --enable-gd-native-ttf \
 --with-openssl \
 --with-fpm-user=apache \
 --with-fpm-group=apache \
 --with-libdir=lib64 \
 --enable-ftp \
 --with-imap \
 --with-imap-ssl \
 --with-kerberos \
 --with-gettext \
 --enable-fpm

Install

make
make install

If you install on nginx then replace (–with-fpm-user=apache \ –with-fpm-group=apache \)  with

–with-fpm-user=nginx \ –with-fpm-group=nginx \

If somehow do not install mcrypt (libmcrypt) then install it

Copy php.ini and php-fpm.conf in right location

cp /usr/local/src/php5-build/php-5.3.9/php.ini-production /opt/phpfcgi-5.3.9/lib/php.ini
cp /opt/phpfcgi-5.3.9/etc/php-fpm.conf.default /opt/phpfcgi-5.3.9/etc/php-fpm.conf
nano /opt/phpfcgi-5.3.9/etc/php-fpm.conf

Add

###############

Change listen port (from 9000 to 8999 )

listen = 127.0.0.1:8999

user=apache

group=apache

If is instaled under nginx replace apache with nginx

At the and of file add

include=/opt/phpfcgi-5.3.9/etc/pool.d/*.conf

#############################

Create dirtectory pool.d

mkdir /opt/phpfcgi-5.3.9/etc/pool.d

Create file php-5.3.9-fpm

/etc/init.d/php-5.3.9-fpm
nano /etc/init.d/php-5.3.9-fpm

Add

#! /bin/sh
 ### BEGIN INIT INFO
 # Provides: php-5.3.9-fpm
 # Required-Start: $all
 # Required-Stop: $all
 # Default-Start: 2 3 4 5
 # Default-Stop: 0 1 6
 # Short-Description: starts php-5.3.9-fpm
 # Description: starts the PHP FastCGI Process Manager daemon
 ### END INIT INFO
 php_fpm_BIN=/opt/phpfcgi-5.3.9/sbin/php-fpm
 php_fpm_CONF=/opt/phpfcgi-5.3.9/etc/php-fpm.conf
 php_fpm_PID=/opt/phpfcgi-5.3.9/var/run/php-fpm.pid
 php_opts="--fpm-config $php_fpm_CONF"
 wait_for_pid () {
 try=0
 while test $try -lt 35 ; do
 case "$1" in
 'created')
 if [ -f "$2" ] ; then
 try=''
 break
 fi
 ;;
 'removed')
 if [ ! -f "$2" ] ; then
 try=''
 break
 fi
 ;;
 esac
 echo -n .
 try=`expr $try + 1`
 sleep 1
 done
 }
 case "$1" in
 start)
 echo -n "Starting php-fpm "
 $php_fpm_BIN $php_opts
 if [ "$?" != 0 ] ; then
 echo " failed"
 exit 1
 fi
 wait_for_pid created $php_fpm_PID
 if [ -n "$try" ] ; then
 echo " failed"
 exit 1
 else
 echo " done"
 fi
 ;;
 stop)
 echo -n "Gracefully shutting down php-fpm "
 if [ ! -r $php_fpm_PID ] ; then
 echo "warning, no pid file found - php-fpm is not running ?"
 exit 1
 fi
 kill -QUIT `cat $php_fpm_PID`
 wait_for_pid removed $php_fpm_PID
 if [ -n "$try" ] ; then
 echo " failed. Use force-exit"
 exit 1
 else
 echo " done"
 echo " done"
 fi
 ;;
 force-quit)
 echo -n "Terminating php-fpm "
 if [ ! -r $php_fpm_PID ] ; then
 echo "warning, no pid file found - php-fpm is not running ?"
 exit 1
 fi
 kill -TERM `cat $php_fpm_PID`
 wait_for_pid removed $php_fpm_PID
 if [ -n "$try" ] ; then
 echo " failed"
 exit 1
 else
 echo " done"
 fi
 ;;
 restart)
 $0 stop
 $0 start
 ;;
 reload)
 echo -n "Reload service php-fpm "
 if [ ! -r $php_fpm_PID ] ; then
 echo "warning, no pid file found - php-fpm is not running ?"
 exit 1
 fi
 kill -USR2 `cat $php_fpm_PID`
 echo " done"
 ;;
 *)
 echo "Usage: $0 {start|stop|force-quit|restart|reload}"
 exit 1
 ;;
 esac
chmod 755 /etc/init.d/php-5.3.9-fpm
chkconfig --levels 235 php-5.3.9-fpm on

If return an match pattern error it’s not a problem (pool.d directory is empty)

Restart system

reboot

We finish installation for PHP-5.3.9

################################

Install  PHP-5.4

yum install centos-release-SCL
yum install php54 php54-php-cli php54-php-mysql php54-php-gd

########################

Or manual installation for PHP-5.4.1

Install 5.4.1 – PHP-FMP

mkdir /opt/php-5.4.1
mkdir /usr/local/src/php5-build
cd /usr/local/src/php5-build
wget http://museum.php.net/php5/php-5.4.1.tar.bz2
tar jxf php-5.4.1.tar.bz2
cd php-5.4.1
yum groupinstall 'Development Tools'
yum install libxml2-devel libXpm-devel gmp-devel libicu-devel t1lib-devel aspell-devel openssl-devel bzip2-devel libcurl-devel libjpeg-devel libvpx-devel libpng-devel freetype-devel readline-devel libtidy-devel libxslt-devel libmcrypt-devel pcre-devel curl-devel mysql-devel ncurses-devel gettext-devel net-snmp-devel libevent-devel libtool-ltdl-devel libc-client-devel postgresql-devel

Configuration (lonf command)

./configure \
 --prefix=/opt/php-5.4.1 \
 --with-pdo-pgsql \
 --with-zlib-dir \
 --with-freetype-dir \
 --enable-mbstring \
 --with-libxml-dir=/usr \
 --enable-soap \
 --enable-calendar \
 --with-curl \
 --with-mcrypt \
 --with-zlib \
 --with-gd \
 --with-pgsql \
 --disable-rpath \
 --enable-inline-optimization \
 --with-bz2 \
 --with-zlib \
 --enable-sockets \
 --enable-sysvsem \
 --enable-sysvshm \
 --enable-pcntl \
 --enable-mbregex \
 --with-mhash \
 --enable-zip \
 --with-pcre-regex \
 --with-mysql \
 --with-pdo-mysql \
 --with-mysqli \
 --with-jpeg-dir=/usr \
 --with-png-dir=/usr \
 --enable-gd-native-ttf \
 --with-openssl \
 --with-libdir=lib64 \
 --enable-ftp \
 --with-imap \
 --with-imap-ssl \
 --with-kerberos \
 --with-gettext \
 --enable-fpm

If u install under apache before  –enable-fpm add

–with-fpm-user=apache \

–with-fpm-group=apache \

Install:

make
make install

Copy php.ini in directories

cp /usr/local/src/php5-build/php-5.4.1/php.ini-production /opt/php-5.4.1/lib/php.ini
cp /opt/php-5.4.1/etc/php-fpm.conf.default /opt/php-5.4.1/etc/php-fpm.conf

Edit /opt/php-5.4.1/etc/php-fpm.conf

nano /opt/php-5.4.1/etc/php-fpm.conf

Modify listen port (from 9000 in 8998) , on user and group add what u need (apache or nginx) and at the end of file add

include=/opt/php-5.4.1/etc/pool.d/*.conf

It will look like

[...]
 pid = run/php-fpm.pid
 [...]
 user = apache
 group = apache
 [...]
 listen = 127.0.0.1:8998
 [...]
 include=/opt/php-5.4.1/etc/pool.d/*.conf
mkdir /opt/php-5.4.1/etc/pool.d

Create file php-5.4.1-fpm

nano /etc/init.d/php-5.4.1-fpm

Add

#! /bin/sh
 ### BEGIN INIT INFO
 # Provides: php-5.4.1-fpm
 # Required-Start: $all
 # Required-Stop: $all
 # Default-Start: 2 3 4 5
 # Default-Stop: 0 1 6
 # Short-Description: starts php-5.4.1-fpm
 # Description: starts the PHP FastCGI Process Manager daemon
 ### END INIT INFO
 php_fpm_BIN=/opt/php-5.4.1/sbin/php-fpm
 php_fpm_CONF=/opt/php-5.4.1/etc/php-fpm.conf
 php_fpm_PID=/opt/php-5.4.1/var/run/php-fpm.pid
 php_opts="--fpm-config $php_fpm_CONF"
 wait_for_pid () {
 try=0
 while test $try -lt 35 ; do
 case "$1" in
 'created')
 if [ -f "$2" ] ; then
 try=''
 break
 fi
 ;;
 'removed')
 if [ ! -f "$2" ] ; then
 try=''
 break
 fi
 ;;
 esac
 echo -n .
 try=`expr $try + 1`
 sleep 1
 done
 }
 case "$1" in
 start)
 echo -n "Starting php-fpm "
 $php_fpm_BIN $php_opts
 if [ "$?" != 0 ] ; then
 echo " failed"
 exit 1
 fi
 wait_for_pid created $php_fpm_PID
 if [ -n "$try" ] ; then
 echo " failed"
 exit 1
 else
 echo " done"
 fi
 ;;
 stop)
 echo -n "Gracefully shutting down php-fpm "
 if [ ! -r $php_fpm_PID ] ; then
 echo "warning, no pid file found - php-fpm is not running ?"
 exit 1
 fi
 kill -QUIT `cat $php_fpm_PID`
 wait_for_pid removed $php_fpm_PID
 if [ -n "$try" ] ; then
 echo " failed. Use force-exit"
 exit 1
 else
 echo " done"
 echo " done"
 fi
 ;;
 force-quit)
 echo -n "Terminating php-fpm "
 if [ ! -r $php_fpm_PID ] ; then
 echo "warning, no pid file found - php-fpm is not running ?"
 exit 1
 fi
 kill -TERM `cat $php_fpm_PID`
 wait_for_pid removed $php_fpm_PID
 if [ -n "$try" ] ; then
 echo " failed"
 exit 1
 else
 echo " done"
 fi
 ;;
 restart)
 $0 stop
 $0 start
 ;;
 reload)
 echo -n "Reload service php-fpm "
 if [ ! -r $php_fpm_PID ] ; then
 echo "warning, no pid file found - php-fpm is not running ?"
 exit 1
 fi
 kill -USR2 `cat $php_fpm_PID`
 echo " done"
 ;;
 *)
 echo "Usage: $0 {start|stop|force-quit|restart|reload}"
 exit 1
 ;;
 esac
chmod 755 /etc/init.d/php-5.4.1-fpm
chkconfig --levels 235 php-5.4.1-fpm on
/etc/init.d/php-5.4.1-fpm start

PHP 5.4.1 – FastCgi

mkdir /opt/phpfcgi-5.4.1
mkdir /usr/local/src/php5-build
cd /usr/local/src/php5-build
wget http://museum.php.net/php5/php-5.4.1.tar.bz2
tar jxf php-5.4.1.tar.bz2
cd php-5.4.1
yum groupinstall 'Development Tools'

Install dependency (long command)

yum install libxml2-devel libXpm-devel gmp-devel libicu-devel t1lib-devel aspell-devel openssl-devel bzip2-devel libcurl-devel libjpeg-devel libvpx-devel libpng-devel freetype-devel readline-devel libtidy-devel libxslt-devel libmcrypt-devel pcre-devel curl-devel mysql-devel ncurses-devel gettext-devel net-snmp-devel libevent-devel libtool-ltdl-devel libc-client-devel postgresql-devel

Configuration with next command (long command)

./configure \
 --prefix=/opt/phpfcgi-5.4.1 \
 --with-pdo-pgsql \
 --with-zlib-dir \
 --with-freetype-dir \
 --enable-mbstring \
 --with-libxml-dir=/usr \
 --enable-soap \
 --enable-calendar \
 --with-curl \
 --with-mcrypt \
 --with-zlib \
 --with-gd \
 --with-pgsql \
 --disable-rpath \
 --enable-inline-optimization \
 --with-bz2 \
 --with-zlib \
 --enable-sockets \
 --enable-sysvsem \
 --enable-sysvshm \
 --enable-pcntl \
 --enable-mbregex \
 --with-mhash \
 --enable-zip \
 --with-pcre-regex \
 --with-mysql \
 --with-pdo-mysql \
 --with-mysqli \
 --with-jpeg-dir=/usr \
 --with-png-dir=/usr \
 --enable-gd-native-ttf \
 --with-openssl \
 --with-fpm-user=apache \
 --with-fpm-group=apache \
 --with-libdir=lib64 \
 --enable-ftp \
 --with-imap \
 --with-imap-ssl \
 --with-kerberos \
 --with-gettext \
 --enable-cgi
make
make install
cp /usr/local/src/php5-build/php-5.4.1/php.ini-production /opt/phpfcgi-5.4.1/lib/php.ini

Reboot

If u want u can install memcache, memcached

yum install php-pear
cd /opt/phpfcgi-5.4.1/etc
pecl -C ./pear.conf update-channel
pecl -C ./pear.conf install memcache
nano /opt/phpfcgi-5.4.1/lib/php.ini

Add to the end of file

########################

extension=memcache.so

########################

Install memcached extension

yum install libmemcached-devel
pecl -C ./pear.conf install memcached
nano /opt/phpfcgi-5.4.1/lib/php.ini

Add to the end

#####################

extension=memcached.so

########################

Done!

Leave a Reply

Your email address will not be published. Required fields are marked *