Install multiple version of php on CentOS 6.5

This is a how-to of install php 5.3 an dphp 5.5 on one server, CentOS and use them simultaneously.

It is based on CentOS 6.5, 64bit for Apache only.

1) Enable rpmforge and epel yum repository

wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -ivh epel-release-6-8.noarch.rpm

 

2) Install php 5.3

CentOS has php 5.3 built-in-box, simply install it with yum

yum install php php-mysql php-mbstring php-mcrypt

 

 

3) Compile and install php 5.5 from source

For php 5.5, we prefer to install it from source, the point is to install php at different location, which does not conflict with the php 5.3.

PHP 5.3 is installed as an apache module, we can only use one version of php at the same time. If we need to run different version of php at the same time, fastcgi and php-fpm works on it.

Build and install php 5.5 with fpm enabled, the latest version of php 5.5 is php 5.5.12.

3.1) Install required dev packages

yum install gcc libxml2-devel bzip2-devel zlib-devel \

    curl-devel libmcrypt-devel libjpeg-devel \

    libpng-devel gd-devel mysql-devel


3.2) Compile and install

wget http://ca2.php.net/get/php-5.5.12.tar.bz2/from/this/mirror

 

tar -xjf mirror

 

cd php-5.5.12

./configure --prefix=/usr/local/php55 \

    --with-config-file-path=/etc/php55 \

    --with-config-file-scan-dir=/etc/php55/php.d \

    --enable-fpm \

    --with-fpm-user=apache \

    --with-fpm-group=apache \

    --with-libdir=lib64 \

    --with-mysql \

    --with-mysqli \

    --enable-mbstring \

    --disable-debug \

    --disable-rpath \

    --with-bz2 \

    --with-curl \

    --with-gettext \

    --with-iconv \

    --with-openssl \

    --with-gd \

    --with-mcrypt \

    --with-pcre-regex \

    --with-zlib

 

make -j4 && sudo make install

mkdir /etc/php55

cp php.ini-production /etc/php55/php.ini

sed -i -e 's#php_fpm_CONF=\${prefix}/etc/php-fpm.conf#php_fpm_CONF=/etc/php55/php-fpm.conf#' \

    sapi/fpm/init.d.php-fpm

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod a+x /etc/init.d/php-fpm

/sbin/chkconfig --add php-fpm

/sbin/chkconfig php-fpm on

cp sapi/fpm/php-fpm.conf /etc/php55/



3.3 Configure php-fpm
Edit /etc/php55/php-fpm.conf, change some settings. This step is mainly to uncomment some settings.

vi /etc/php55/php-fpm.conf

 


 


Then, start php-fpm

/etc/init.d/php-fpm start


3.4) Install and setup mod_fastcgi


4) Prepare hosts and add web sites settings
4.1) Add the following line to /etc/hosts

127.0.0.1 php53.example.com php55.example.com

4.2) Create web document root and drop and index.php under it to show php information.

mkdir /var/www/fcgi-bin

for i in {1..2}; do

    web_root=/var/www/web$i

    mkdir $web_root

    echo "<?php phpinfo(); ?>" > $web_root/index.php

done


4.3) Create Apache config file(append it to httpd.conf)

vi /etc/httpd/conf/httpd.conf

 

Modify httpd.conf Per below

NameVirtualHost *:80

 

# module settings

# mod_fastcgi with php-fpm

 

<IfModule mod_fastcgi.c>

        FastCgiExternalServer /var/www/fcgi-bin/php-fpm -host 127.0.0.1:9000

</IfModule>

 

# virtual hosts...

 

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

#1st virtual host, use mod_php, run php-5.3.3

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

<VirtualHost *:80>

        ServerName php53.example.com

        DocumentRoot "/var/www/web1"

 

        <ifmodule mod_php5.c>

                <FilesMatch \.php$>

                        AddHandler php5-script .php

                </FilesMatch>

        </IfModule>

 

        <Directory "/var/www/web1">

                DirectoryIndex index.php index.html index.htm

                Options -Indexes FollowSymLinks

                Order allow,deny

                Allow from all

        </Directory>

 

</VirtualHost>


 

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

#2nd virtual host, use mod_fastcgi + php-fpm, run php-5.5.12

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

<VirtualHost *:80>

        ServerName php55.example.com

        DocumentRoot "/var/www/web2"

 

 

        <IfModule mod_fastcgi.c>

                ScriptAlias /fcgi-bin/ /var/www/fcgi-bin/

                AddHandler php5-fastcgi .php

                Action php5-fastcgi /fcgi-bin/php-fpm

        </IfModule>

 

        <Directory "/var/www/web2">

                DirectoryIndex index.php index.html index.htm

                Options -Indexes FollowSymLinks +ExecCGI

                Order allow,deny

                Allow from all

        </Directory>

 

</VirtualHost>


 

4.4) Restart apache. Visit these two sites and view phpinfo page.

service httpd restart



 

http://php55.example.com

You can use the one of the virtual host as a template to create new virtual host.

 

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Installing Fail2ban

  Installing Fail2ban Installing Fail2ban on Ubuntu Server 16.04 is simple. Run the following...

How to display sockets summary and all open network ports with ss command

How to display sockets summary with ss command # ss -s How to display all open network ports...

How to find a folder in Linux using the command line

  I am a new Linux user. How do I find files and folders in Linux using the bash command line?...

How to scan for viruses with ClamAV on Ubuntu

ClamAV There aren't many viruses made for Linux distributions and as such, most people who use...

How to setup a UFW firewall on Ubuntu 18.04 LTS server

How do I setup a firewall with UFW (uncomplicated firewall) on an Ubuntu Linux 18.04 LTS server...