内容纲要

安装 nginx

[code]
$ vi /etc/yum.repos.d/nginx.repo
[/code]

附加

[code]
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1
[/code]

[code]
$ sudo yum install nginx
[/code]

[code]
$ sudo systemctl enable nginx

$ sudo systemctl start nginx
$ sudo systemctl stop nginx
$ sudo systemctl restart nginx
$ sudo systemctl status nginx

[/code]

开放防火墙端口

[code]
$ sudo firewall-cmd –permanent –zone=public –add-service=http
$ sudo firewall-cmd –permanent –zone=public –add-service=https
$ sudo firewall-cmd –reload
[/code]

测试

[code]
$ sudo ss -tulpn
[/code]

IP 地址

[code]
$ ip a
[/code]

[code]
http://IP
[/code]

[code]
$ curl -I http://10.21.136.13
$ curl http://10.21.136.13
[/code]

安装 PHP 7.2

[code]
sudo yum -y install epel-release

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

sudo yum install yum-utils

sudo yum-config-manager –enable remi-php72

sudo yum update

sudo yum search php72 | more

sudo yum search php72 | egrep ‘fpm|gd|mysql|memcache’

sudo yum install php72

sudo yum install php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache
[/code]

[code]
php –version

php72 –modules
[/code]

[code]
sudo systemctl enable php72-php-fpm.service
[/code]

[code]
sudo systemctl start php72-php-fpm.service
sudo systemctl stop php72-php-fpm.service
sudo systemctl restart php72-php-fpm.service

sudo systemctl status php72-php-fpm.service
[/code]

配置 Nginx

[code]
$ egrep ‘^(user|group)’ /etc/nginx/nginx.conf
[/code]

输出

[code]
user nginx;
[/code]

编辑 vi /etc/opt/remi/php72/php-fpm.d/www.conf

[code]
$ sudo vi /etc/opt/remi/php72/php-fpm.d/www.conf
[/code]

设置 user 和 group 为 nginx

[code]
user = nginx
group = nginx
[/code]

保存,重启 php-fpm service

[code]
$ sudo systemctl restart php72-php-fpm.service
[/code]

更新 nginx 配置

[code]
$ sudo vi /etc/nginx/conf.d/default.conf
[/code]

[code]
## enable php support ##
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
[/code]

[code]
$ sudo systemctl restart nginx
[/code]

在 /usr/share/nginx/html/ 创建一个脚本 foo.php

[code]
$ sudo vi /usr/share/nginx/html/foo.php
[/code]

[code]
<?php // test script for CentOS/RHEL 7+PHP 7.2+Nginx phpinfo(); ?>
[/code]

然后测试 http://IP/foo.php

发表评论

电子邮件地址不会被公开。 必填项已用*标注