一、安装nginx
1、加载EPLE软件仓库
sudo yum install epel-release
2、安装nginx
sudo yum install nginx
3、启动nginx
sudo systemctl start nginx
二、安装php 7.2
0、如果安装过php先卸载
sudo yum -y remove php*
1、加载软件源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2、安装各种扩展
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
2.1 如果要支持pecl
yum install php72w-pear
三、配置nginx服务器的php
1、删除原来的配置文件,复制默认配置文件
cd /usr/share/nginx/
rm -rf nginx.conf
cp nginx.conf.default nginx.conf
2、修改配置文件
vim nginx.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
# 修改1:这里新增了index.php
index index.html index.htm index.php;
# 修改2:这里新增url重写(path)
try_files $uri $uri/ /index.php$is_args$args;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#修改3:解开php支持的注释
location ~ \.php$ {
root html;
#默认就使用php-fpm
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#修改4:修改fastcig的路径
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
#保存并关闭
3、重启nginx
systemctl restart nginx
4、编写测试文件测试
cd /usr/share/nginx/html/
vim phptest.php
<?php
phpinfo();
#保存并退出
网友评论