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 nginx
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-fpm 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-fpm php70-php-gd php70-php-json php70-php-mbstring php70-php-openssl php70-php-pdo php70-php-tokenizer php70-php-xml php70-php-zip
Setup the permissions and listen parameters on the configuration files for PHP-FPM.
# PHP 5.6
vim /opt/remi/php56/root/etc/php-fpm.d/www.conf
# PHP 7.0
vim /etc/opt/remi/php70/php-fpm.d/www.conf
www.conf
user = nginx
group = nginx
php56/root/etc/php-fpm.d/www.conf
listen = 127.0.0.1:9000
php70/root/etc/php-fpm.d/www.conf
listen = 127.0.0.1:9001
Change directory to the default web directory.
# CentOS/RHEL 6
cd /usr/share/nginx/www
# CentOS/RHEL 7
cd /usr/share/nginx/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 var_export($_SERVER); phpinfo(); ?>
Two server blocks will be created, one for each site, on ports 81 and 82 respectively.
cd /etc/nginx/conf.d
vim php56-example.conf
vim php70-example.conf
php56-example.conf
server {
listen 81 default_server;
server_name _;
root /usr/share/nginx/html/php56-example;
#error_page 404 errors/404.html;
access_log /var/log/nginx/php56-example.access.log;
index index.php index.html index.htm;
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
#fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param PHP_FCGI_CHILDREN 4;
fastcgi_param PHP_FCGI_MAX_REQUESTS 1000;
}
location ~ /\.ht {
deny all;
}
}
php70-example.conf
server {
listen 82 default_server;
server_name _;
root /usr/share/nginx/html/php70-example;
#error_page 404 errors/404.html;
access_log /var/log/nginx/php70-example.access.log;
index index.php index.html index.htm;
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
#fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_pass 127.0.0.1:9001;
fastcgi_param PHP_FCGI_CHILDREN 4;
fastcgi_param PHP_FCGI_MAX_REQUESTS 1000;
}
location ~ /\.ht {
deny all;
}
}
nginx -t
Add the site ports to the whitelist
# Server
semanage port -a -t http_port_t -p tcp 81
semanage port -a -t http_port_t -p tcp 82
# Socket
semanage port -m -t http_port_t -p tcp 9000
semanage port -m -t http_port_t -p tcp 9001
Check the port whitelist
semanage port -l | grep http_port_t
systemctl enable nginx
systemctl restart nginx
systemctl enable php56-php-fpm php70-php-fpm
systemctl restart php56-php-fpm php70-php-fpm
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/nginx/error.log
- [error] 121177#0: *1467 upstream timed out
- This is caused by a timeout from either a regular or a fastcgi upstream. You can increase either the proxy_read_timeout or the fastcgi_read_timeout to fix it.
- References: 1
- http://blog.martinfjordvald.com/2013/04/nginx-config-history-fastcgi_params-versus-fastcgi-conf/
- http://mailman.nginx.org/pipermail/nginx/2012-May/033865.html
- https://serverfault.com/questions/883962/blank-page-nginx-1-10-wordpress-php7-0-fpm
- https://tecadmin.net/install-multiple-php-version-nginx-ubuntu/
- https://www.nginx.com/blog/using-nginx-plus-with-selinux/
- https://www.nginx.com/resources/wiki/start/topics/examples/fastcgiexample/
- https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/
- https://www.nginx.com/resources/wiki/start/topics/examples/server_blocks/
- https://www.rootusers.com/use-selinux-port-labeling-to-allow-services-to-use-non-standard-ports/
- https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/