Chạy nextjs trên centos 7, phần 2, multi PHP

Disable Selinux

sudo setenforce 0
sudo nano /etc/selinux/config
# Chỉnh SELINUX=disabled
reboot

Cài đặt Apache và repository

sudo yum install httpd
sudo yum install epel-release
sudo yum install yum-utils

Cài đặt multi PHP

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum install php56
sudo yum install php72
sudo yum install php80
sudo yum install php56-php-fpm
sudo yum install php74-php-fpm
sudo yum install php80-php-fpm

Liệt kê danh sách install đã cài PHP

sudo yum list installed | grep -i php

Stop php-fpm

sudo systemctl stop php56-php-fpm
sudo systemctl stop php74-php-fpm
sudo systemctl stop php80-php-fpm

Cho phép selinux chạy php-fpm

sudo semanage port -a -t http_port_t -p tcp 9056
sudo semanage port -a -t http_port_t -p tcp 9074
sudo semanage port -a -t http_port_t -p tcp 9080

Đổi cổng cho mỗi php-fpm

sudo sed -i 's/:9000/:9056/' /etc/opt/remi/php56/php-fpm.d/www.conf
sudo sed -i 's/:9000/:9074/' /etc/opt/remi/php74/php-fpm.d/www.conf
sudo sed -i 's/:9000/:9080/' /etc/opt/remi/php80/php-fpm.d/www.conf

Chạy php-fpm

sudo systemctl start php56-php-fpm
sudo systemctl start php74-php-fpm
sudo systemctl start php80-php-fpm

Check php-fpm running

ps aux | grep php-fpm

Tạo đường dẫn cgi-bin

sudo mkdir -p /var/www/cgi-bin

Gọi php56-fcgi

sudo nano /var/www/cgi-bin/php56.fcgi

Điền vào nội dung như sau

#!/bin/bash
exec /bin/php56-cgi

Gọi php74-fcgi

sudo nano /var/www/cgi-bin/php74.fcgi

Điền vào nội dung như sau

#!/bin/bash
exec /bin/php74-cgi

Gọi php80-fcgi

sudo nano /var/www/cgi-bin/php80.fcgi

Điền vào nội dung như sau

#!/bin/bash
exec /bin/php80-cgi

chmod

sudo chmod 755 /var/www/cgi-bin/php56.fcgi
sudo chmod 755 /var/www/cgi-bin/php74.fcgi
sudo chmod 755 /var/www/cgi-bin/php80.fcgi

Config Apache test multi php

sudo nano /etc/httpd/conf.d/php.conf

Điền vào nội dung sau

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
AddHandler php80-fcgi .php

Action php56-fcgi /cgi-bin/php56.fcgi
Action php74-fcgi /cgi-bin/php74.fcgi
Action php80-fcgi /cgi-bin/php80.fcgi

<Directory /var/www/html/php56>
	DirectoryIndex index.php index.html
	AllowOverride all
	Require all granted
	AddHandler php56-fcgi .php
</Directory>

<Directory /var/www/html/php74>
	DirectoryIndex index.php index.html
	AllowOverride all
	Require all granted
	AddHandler php74-fcgi .php
</Directory>

<Directory /var/www/html/php80>
	DirectoryIndex index.php index.html
	AllowOverride all
	Require all granted
	AddHandler php80-fcgi .php
</Directory>

Gõ các lệnh sau

sudo chown -R nangthuyen85 /var/www

sudo mkdir -p /var/www/html/php56
sudo mkdir -p /var/www/html/php74
sudo mkdir -p /var/www/html/php80

echo "<?php phpinfo(); ?>" > /var/www/html/php56/index.php
echo "<?php phpinfo(); ?>" > /var/www/html/php74/index.php
echo "<?php phpinfo(); ?>" > /var/www/html/php80/index.php

sudo systemctl enable httpd
sudo systemctl enable php56-php-fpm
sudo systemctl enable php74-php-fpm
sudo systemctl enable php80-php-fpm
sudo systemctl start httpd
sudo systemctl start php56-php-fpm
sudo systemctl start php74-php-fpm
sudo systemctl start php80-php-fpm