Install Multiple Version of PHP on CentOS 6.5 as Fastcgi

It is a guide of how to install multiple version of PHP on CentOS 6.5 64bit. All different PHP as fastcgi.
It is works on Apache, one web server, each virtualhost has its own different php version support.

0) Prepare the testing environment

Disable SELinux and stop iptables. It is for testing environment. For production machine, you should implement firewall carefully.

setenforce 0
service iptables stop

1) Enable rpmforge and epel yum repository

rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
rpm -ivh epel-release-6-8.noarch.rpm

2) Install required dev packages and Apache, mod_fcgid

yum install gcc libxml2-devel bzip2-devel zlib-devel \
    curl-devel libmcrypt-devel libjpeg-devel \
    libpng-devel gd-devel mysql-devel
yum install httpd mod_fcgid 

3) Create the system startup links for Apache and start it:

chkconfig --levels 235 httpd on
/etc/init.d/httpd restart 

4) Compile and install php 5.5.12

tar -xvzf 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 \
    --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 install
mkdir /etc/php55
cp php.ini-production /etc/php55/php.ini

Edit php.ini

vi /etc/php55/php.ini

Add the following in the end of the file

cgi.fix_pathinfo = 1

Restart Apache

service httpd restart

5) Creating Vhosts For

5.1) Create user and group

groupadd web1
useradd -s /bin/false -d /var/www/web1 -m -g web1 web1
chmod 755 /var/www/web1

5.2) Then we create the document roots and make them owned by the users/groups web1:

mkdir -p /var/www/web1/web
chown web1:web1 /var/www/web1/web

5.3) We will run PHP using suExec; suExec’s document root is /var/www, as the following command shows:

[root@localhost ~]# /usr/sbin/suexec -V
 -D AP_DOC_ROOT="/var/www"
 -D AP_GID_MIN=100
 -D AP_HTTPD_USER="apache"
 -D AP_LOG_EXEC="/var/log/httpd/suexec.log"
 -D AP_SAFE_PATH="/usr/local/bin:/usr/bin:/bin"
 -D AP_UID_MIN=500
 -D AP_USERDIR_SUFFIX="public_html"

5.4) create the wrapper scripts in subdirectories of /var/www/php-fcgi-scripts

mkdir -p /var/www/php-fcgi-scripts/web1
vi /var/www/php-fcgi-scripts/web1/php-fcgi-starter

Enter following into php-fcgi-starter

export PHPRC
exec /usr/local/php55/bin/php-cgi

5.5) The php-fcgi-starter scripts must be executable, and they (and the directories they are in) must be owned by the web site’s user and group:

chmod 755 /var/www/php-fcgi-scripts/web1/php-fcgi-starter
chown -R web1:web1 /var/www/php-fcgi-scripts/web1

5.6) Create Vhost for

vi /etc/httpd/conf/httpd.conf
NameVirtualHost *:80

<VirtualHost *:80>
  DocumentRoot /var/www/web1/web/

  <IfModule mod_fcgid.c>
    SuexecUserGroup web1 web1
    <Directory /var/www/web1/web/>
      Options +ExecCGI
      AllowOverride All
      AddHandler fcgid-script .php
      FCGIWrapper /var/www/php-fcgi-scripts/web1/php-fcgi-starter .php
      Order allow,deny
      Allow from all

  # ErrorLog /var/log/apache2/error.log
  # CustomLog /var/log/apache2/access.log combined
  ServerSignature Off


Restart Apache

service httpd restart

5.7) Now we create a small PHP test file

vi /var/www/web1/web/info.php

Add following content into it.


6) In Browser, you can see following infomation page.


7) Compile and install php 5.4.28 and php 5.3.28

Repeat the step 4, 5, and 6. Just change something respect to php 5.4.28 and php5.3.28.

7.1) php 5.4.28



user web2

group web2



7.2) php 5.3.28



user web3

group web3


Then, I have three hosts on the same one Apache web server at CentOS 6.5 64bit server.

Each host has its own php version installed, from 5.3 to 5.5.

So, you can use the above as a template.