Thiết lập Mutiple Site với các phiên bản PHP khác nhau trên Nginx
1. Cài đặt EPEL
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# yum install yum-utils
# vi /etc/yum.repos.d/nginx.repo
Thêm dòng sau
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
# yum install nginx
# vi /etc/yum.repos.d/mariadb.repo
Thêm dòng sau
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
# yum install MariaDB-client MariaDB-server
# mysql_secure_installation
PHP 7.1
# yum-config-manager --enable remi-php71 [Default]
# yum install php php-common php-fpm
# yum install php-mysql php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt
php-xml php-pecl-apc php-cli php-pear php-pdo
PHP 5.6
# yum install php56 php56-php-common php56-php-fpm
# yum install php56-php-mysql php56-php-pecl-memcache php56-php-pecl-memcached php56-php-gd
php56-php-mbstring php56-php-mcrypt php56-php-xml php56-php-pecl-apc php56-php-cli
php56-php-pear php56-php-pdo
# vi /etc/php-fpm.d/www.conf [PHP 7.1]
# vi /opt/remi/php56/root/etc/php-fpm.d/www.conf [PHP 5.6]
user = nginx
group = nginx
listen = 127.0.0.1:9000 [php-fpm]
listen = 127.0.0.1:9001 [php56-php-fpm]
Khởi động dịch vụ và cho phép khởi động cùng hệ thống
# systemctl enable nginx
# systemctl start nginx
# systemctl enable mariadb
# systemctl start mariadb
---------------- PHP 7.1 ----------------
# systemctl enable php-fpm
# systemctl start php-fpm
---------------- PHP 5.6 ----------------
# systemctl enable php56-fpm
# systemctl start php56-php-fpm
Nếu start dịch vụ không được chúng ta nên tắt SELINUX
# getenforce
# setenforce 0
---------------- Website 1 ----------------
# mkdir -p /var/www/html/example1.com/
# mkdir -p /var/www/html/example2.com/
---------------- Website 2 ----------------
# mkdir -p /var/log/nginx/example1.com/
# mkdir -p /var/log/nginx/example2.com/
---------------- Website 1 ----------------
# chown -R root:nginx /var/www/html/example1.com/
# chmod -R 755 /var/www/html/example1.com/
# chown -R root:nginx /var/log/nginx/example1.com/
# chmod -R 660 /var/log/nginx/example1.com/
---------------- Website 2 ----------------
# chown -R root:nginx /var/www/html/example2.com/
# chmod -R 755 /var/www/html/example2.com/
# chown -R root:nginx /var/log/nginx/example2.com/
# chmod -R 660 /var/log/nginx/example2.com/
# vi /etc/nginx/conf.d/example1.com.conf
Thêm dòng sau:
server {
listen 80;
server_name example1.com www.example1.com;
root /var/www/html/example1.com/;
index index.php index.html index.htm;
#charset koi8-r;
access_log /var/log/nginx/example1.com/example1_access_log;
error_log /var/log/nginx/example1.com/example1_error_log error;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /var/www/html/example1.com/;
fastcgi_pass 127.0.0.1:9000; #set port for php-fpm to listen on
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include /etc/nginx/fastcgi_params;
}
}
# vi /etc/nginx/conf.d/example2.com.conf
Thêm dòng sau:
server {
listen 80;
server_name example2.com www.example2.com;
root /var/www/html/example2.com/;
index index.php index.html index.htm;
#charset koi8-r;
access_log /var/log/nginx/example2.com/example2_access_log;
error_log /var/log/nginx/example2.com/example2_error_log error;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /var/www/html/example2.com/;
fastcgi_pass 127.0.0.1:9001; #set port for php56-php-fpm to listen on
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include /etc/nginx/fastcgi_params;
}
}
include /etc/nginx/conf.d/*.conf;
# echo "<?php phpinfo(); ?>" > /var/www/html/example1.com/info.php
# echo "<?php phpinfo(); ?>" > /var/www/html/example2.com/info.php
# nginx -t
# systemctl restart nginx php-fpm php56-php-fpm
Kiểm tra kết quả
No comments: