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

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 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

wget http://us1.php.net/get/php-5.5.12.tar.gz/from/this/mirror
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 \
    --enable-cgi
make 
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 web1.example.com

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

#!/bin/sh
PHPRC=/etc/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
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 web1.example.com

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

<VirtualHost *:80>
  ServerName web1.example.com
  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
    </Directory>
  </IfModule>

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

</VirtualHost>

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.

<?php
phpinfo();
?>

6) In Browser, you can see following infomation page.
web1-php55-fastcgi

 

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

http://us1.php.net/get/php-5.4.28.tar.gz/from/this/mirror

web2.example.com

/usr/local/php54

/etc/php54

user web2

group web2

web2-php54-fastcgi

 

7.2) php 5.3.28

http://us1.php.net/get/php-5.3.28.tar.gz/from/this/mirror

web3.example.com

/usr/local/php53

/etc/php53

user web3

group web3

web3-php53-fastcgi

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.

David Yin

David is a blogger, geek, and web developer — founder of FreeInOutBoard.com. If you like his post, you can say thank you here

4 Replies to “Install Multiple Version of PHP on CentOS 6.5 as Fastcgi

  1. Hi, I’m trying to follow step by step your lesson but after all I’ve got this error:
    [Mon Jun 01 02:31:12 2015] [error] (13)Permission denied: mod_fcgid: couldn’t bind unix domain socket /var/run/mod_fcgid/10154.63
    [Mon Jun 01 02:31:12 2015] [warn] (13)Permission denied: mod_fcgid: spawn process /var/www/php-fcgi-scripts/web1/php-fcgi-starter error

    And nothing happen. Just error 503 “Service Temporarily Unavailable”…

  2. Hi, I’m trying to follow step by step your lesson but after all I’ve got this error:
    [Mon Jun 01 02:31:12 2015] [error] (13)Permission denied: mod_fcgid: couldn’t bind unix domain socket /var/run/mod_fcgid/10154.63
    [Mon Jun 01 02:31:12 2015] [warn] (13)Permission denied: mod_fcgid: spawn process /var/www/php-fcgi-scripts/web1/php-fcgi-starter error

    And nothing happen. Just error 503 “Service Temporarily Unavailable”…

Leave a Reply

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