参考: https://blog.csdn.net/u013474436/article/details/52972699
第一步: 安装php
安装PHP7.2
(1)yum install epel-release
(2)rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装php对应的模块(分2种方式):
(3->1)第一种: yum install php72w
(3->2)第二种: yum list|grep php72, 然后依次安装对应的php模块
[root@localhost ~]# yum list|grep php72
mod_php72w.x86_64 7.2.31-2.w7 webtatic
php72w-bcmath.x86_64 7.2.31-2.w7 webtatic
php72w-cli.x86_64 7.2.31-2.w7 webtatic
php72w-common.x86_64 7.2.31-2.w7 webtatic
php72w-dba.x86_64 7.2.31-2.w7 webtatic
php72w-devel.x86_64 7.2.31-2.w7 webtatic
php72w-embedded.x86_64 7.2.31-2.w7 webtatic
php72w-enchant.x86_64 7.2.31-2.w7 webtatic
php72w-fpm.x86_64 7.2.31-2.w7 webtatic
php72w-gd.x86_64 7.2.31-2.w7 webtatic
php72w-imap.x86_64 7.2.31-2.w7 webtatic
php72w-interbase.x86_64 7.2.31-2.w7 webtatic
php72w-intl.x86_64 7.2.31-2.w7 webtatic
php72w-ldap.x86_64 7.2.31-2.w7 webtatic
php72w-mbstring.x86_64 7.2.31-2.w7 webtatic
php72w-mysql.x86_64 7.2.31-2.w7 webtatic
php72w-mysqlnd.x86_64 7.2.31-2.w7 webtatic
php72w-odbc.x86_64 7.2.31-2.w7 webtatic
php72w-opcache.x86_64 7.2.31-2.w7 webtatic
php72w-pdo.x86_64 7.2.31-2.w7 webtatic
php72w-pdo_dblib.x86_64 7.2.31-2.w7 webtatic
php72w-pear.noarch 1:1.10.12-1.w7 webtatic
php72w-pecl-apcu.x86_64 5.1.18-1.w7 webtatic
php72w-pecl-apcu-devel.x86_64 5.1.18-1.w7 webtatic
php72w-pecl-geoip.x86_64 1.1.1-1.2.w7 webtatic
php72w-pecl-igbinary.x86_64 3.1.2-1.w7 webtatic
php72w-pecl-igbinary-devel.x86_64 3.1.2-1.w7 webtatic
php72w-pecl-imagick.x86_64 3.4.4-1.2.w7 webtatic
php72w-pecl-imagick-devel.x86_64 3.4.4-1.2.w7 webtatic
php72w-pecl-libsodium.x86_64 1.0.6-1.2.w7 webtatic
php72w-pecl-memcached.x86_64 3.1.5-1.w7 webtatic
php72w-pecl-mongodb.x86_64 1.7.4-1.w7 webtatic
php72w-pecl-redis.x86_64 3.1.6-1.w7 webtatic
php72w-pecl-xdebug.x86_64 2.9.6-1.w7 webtatic
php72w-pgsql.x86_64 7.2.31-2.w7 webtatic
php72w-phpdbg.x86_64 7.2.31-2.w7 webtatic
php72w-process.x86_64 7.2.31-2.w7 webtatic
php72w-pspell.x86_64 7.2.31-2.w7 webtatic
php72w-recode.x86_64 7.2.31-2.w7 webtatic
php72w-snmp.x86_64 7.2.31-2.w7 webtatic
php72w-soap.x86_64 7.2.31-2.w7 webtatic
php72w-sodium.x86_64 7.2.31-2.w7 webtatic
php72w-tidy.x86_64 7.2.31-2.w7 webtatic
php72w-xml.x86_64 7.2.31-2.w7 webtatic
php72w-xmlrpc.x86_64 7.2.31-2.w7 webtatic
这里安装所有扩展: yum install -y mod_php72w php72w-bcmath php72w-cli php72w-common php72w-dba php72w-devel php72w-embedded php72w-enchant php72w-fpm php72w-gd php72w-imap php72w-interbase php72w-intl php72w-ldap php72w-mbstring php72w-mysql php72w-mysqlnd php72w-odbc php72w-opcache php72w-pdo php72w-pdo_dblib php72w-pear php72w-pecl-apcu php72w-pecl-apcu-devel php72w-pecl-geoip php72w-pecl-igbinary php72w-pecl-igbinary-devel php72w-pecl-imagick php72w-pecl-imagick-devel php72w-pecl-libsodium php72w-pecl-memcached php72w-pecl-mongodb php72w-pecl-redis php72w-pecl-xdebug php72w-pgsql php72w-phpdbg php72w-process php72w-pspell php72w-recode php72w-snmp php72w-soap php72w-sodium php72w-tidy php72w-xml php72w-xmlrpc --skip-broken
第二步: 安装nginx
yum install -y nginx
第三步: 配置nginx.conf配置文件
[root@shj nginx]# vim /etc/nginx/nginx.conf
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# 新增如下内容,用于解析PHP动态请求的内容
location ~ \.php$ {
include /etc/nginx/fastcgi.conf; # 包含nginx的fastcgi.conf配置文件
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000; # 将PHP动态请求,转发到9000端口的服务上去
}
}
}
第四步:启动nginx服务, 启动php-fpm服务(php-fpm服务默认监听的端口就是9000)
[root@shj ~]# service nginx start
[root@shj ~]# service php-fpm start
查看服务信息: 9000端口是php-fpm服务, 80是nginx的web服务
[root@shj nginx]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 10218/php-fpm: mast
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10177/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7390/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7579/master
tcp6 0 0 :::80 :::* LISTEN 10177/nginx: master
tcp6 0 0 :::22 :::* LISTEN 7390/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7579/master
udp 0 0 127.0.0.1:323 0.0.0.0:* 6588/chronyd
udp6 0 0 ::1:323 :::* 6588/chronyd
第五步: 在 /usr/share/nginx/html (nginx的默认web根目录) 目录想创建测试文件test.php
<?php
phpinfo();
访问: http://10.0.0.160/test.php, 结果如下