Update the installed packages.
yum update
Install the EPEL repository.
# CentOS/RHEL 6
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
# CentOS/RHEL 7
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install epel-release
Install the REMI repository.
# CentOS/RHEL 6
rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-6.rpm
# CentOS/RHEL 7
rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-7.rpm
Check that the repositories are correctly installed.
yum repolist
yum install httpd
In this case, PHP 5.6 and 7.0 will be installed
# PHP 5.6
yum install php56 php56-php-bcmath php56-cli php56-php-ctype php56-php-gd php56-php-json php56-php-mbstring php56-php-openssl php56-php-pdo php56-php-tokenizer php56-php-xml php56-php-zip
# PHP 7.0
yum install php70 php70-php-bcmath php70-cli php70-php-ctype php70-php-gd php70-php-json php70-php-mbstring php70-php-openssl php70-php-pdo php70-php-tokenizer php70-php-xml php70-php-zip
yum install mod_fcgid
Open the configuration file on /etc/httpd/conf.d/php.conf and remove or comment the following lines.
<FilesMatch \.phps$>
SetHandler application/x-httpd-php-source
</FilesMatch>
Two handlers will be created, one for each PHP version installed.
# PHP 5.6
vim /var/www/cgi-bin/php56.fastcgi
chmod +x /var/www/cgi-bin/php56.fastcgi
chown apache:apache /var/www/cgi-bin/php56.fastcgi
# PHP 7.0
vim /var/www/cgi-bin/php70.fastcgi
chmod +x /var/www/cgi-bin/php70.fastcgi
chown apache:apache /var/www/cgi-bin/php70.fastcgi
php56.fastcgi
#!/bin/bash
PHPRC="/opt/remi/php56/root/etc/php.ini"
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
export PHPRC
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec /usr/bin/php56-cgi
php70.fastcgi
#!/bin/bash
PHPRC="/opt/remi/php70/root/etc/php.ini"
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
export PHPRC
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec /usr/bin/php70-cgi
Change directory to the default web directory.
# CentOS/RHEL 6
cd /var/www
# CentOS/RHEL 7
cd /var/www/html
Create the folders each site.
mkdir php56-example php70-example
Create the index files for each site.
vim php56-example/index.php
vim php70-example/index.php
index.php
<?php phpinfo(); ?>
Open the configuration file on /etc/httpd/conf/httpd.conf and make sure the DirectoryIndex is similar to the following.
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
Open the configuration file on /etc/httpd/conf/httpd.conf and add the following ports.
Listen 81
Listen 82
Two vhosts will be created, one for each site, on ports 81 and 82 respectively.
cd /etc/httpd/conf.d
vim php56-example.conf
vim php70-example.conf
php56-example.conf
<VirtualHost *:81>
ServerName php56-example
ServerAdmin [email protected]
DocumentRoot /var/www/html/php56-example
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/html/php56-example">
Options +Indexes +FollowSymLinks +ExecCGI
AddHandler php-fastcgi .php
Action php-fastcgi /cgi-bin/php56.fastcgi
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
php70-example.conf
<VirtualHost *:82>
ServerName php70-example
ServerAdmin [email protected]
DocumentRoot /var/www/html/php70-example
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/html/php70-example">
Options +Indexes +FollowSymLinks +ExecCGI
AddHandler php-fastcgi .php
Action php-fastcgi /cgi-bin/php70.fastcgi
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
service httpd restart
sudo firewall-cmd --permanent --add-port=81/tcp
sudo firewall-cmd --permanent --add-port=82/tcp
sudo firewall-cmd --reload
- Typical log locations
- /var/log/httpd/error_log
- [cgi:error] AH01215
- Description: Usually this is caused by incorrect line endings on the .fastcgi files. Change the end of line sequence from CRLF to LF or recreate the file using vim.
- References: 1