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.

<br />
setenforce 0<br />
service iptables stop<br />

1) Enable rpmforge and epel yum repository

<br />
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm<br />
rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm<br />
wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm<br />
rpm -ivh epel-release-6-8.noarch.rpm<br />

2) Install required dev packages and Apache, mod_fcgid

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

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

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

4) Compile and install php 5.5.12

<br />
wget http://us1.php.net/get/php-5.5.12.tar.gz/from/this/mirror<br />
tar -xvzf mirror<br />
cd php-5.5.12<br />
./configure --prefix=/usr/local/php55 \<br />
    --with-config-file-path=/etc/php55 \<br />
    --with-config-file-scan-dir=/etc/php55/php.d \<br />
    --with-libdir=lib64 \<br />
    --with-mysql \<br />
    --with-mysqli \<br />
    --enable-mbstring \<br />
    --disable-debug \<br />
    --disable-rpath \<br />
    --with-bz2 \<br />
    --with-curl \<br />
    --with-gettext \<br />
    --with-iconv \<br />
    --with-openssl \<br />
    --with-gd \<br />
    --with-mcrypt \<br />
    --with-pcre-regex \<br />
    --with-zlib \<br />
    --enable-cgi<br />
make<br />
make install<br />
mkdir /etc/php55<br />
cp php.ini-production /etc/php55/php.ini<br />

Edit php.ini

<br />
vi /etc/php55/php.ini<br />

Add the following in the end of the file

cgi.fix_pathinfo = 1<br />

Restart Apache

<br />
service httpd restart<br />

5) Creating Vhosts For web1.example.com

5.1) Create user and group

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

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

<br />
mkdir -p /var/www/web1/web<br />
chown web1:web1 /var/www/web1/web<br />

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

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

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

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

Enter following into php-fcgi-starter

#!/bin/sh<br />
PHPRC=/etc/<br />
export PHPRC<br />
export PHP_FCGI_MAX_REQUESTS=5000<br />
export PHP_FCGI_CHILDREN=8<br />
exec /usr/local/php55/bin/php-cgi<br />

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:

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

5.6) Create Vhost for web1.example.com

<br />
vi /etc/httpd/conf/httpd.conf<br />

[...]<br />
NameVirtualHost *:80</p>
<p>&amp;lt;VirtualHost *:80&amp;gt;<br />
  ServerName web1.example.com<br />
  DocumentRoot /var/www/web1/web/</p>
<p>  &amp;lt;IfModule mod_fcgid.c&amp;gt;<br />
    SuexecUserGroup web1 web1<br />
    &amp;lt;Directory /var/www/web1/web/&amp;gt;<br />
      Options +ExecCGI<br />
      AllowOverride All<br />
      AddHandler fcgid-script .php<br />
      FCGIWrapper /var/www/php-fcgi-scripts/web1/php-fcgi-starter .php<br />
      Order allow,deny<br />
      Allow from all<br />
    &amp;lt;/Directory&amp;gt;<br />
  &amp;lt;/IfModule&amp;gt;</p>
<p>  # ErrorLog /var/log/apache2/error.log<br />
  # CustomLog /var/log/apache2/access.log combined<br />
  ServerSignature Off</p>
<p>&amp;lt;/VirtualHost&amp;gt;<br />

Restart Apache

<br />
service httpd restart<br />

5.7) Now we create a small PHP test file

<br />
vi /var/www/web1/web/info.php<br />

Add following content into it.

<br />
&lt;?php<br />
phpinfo();<br />
?&gt;<br />

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.