在虚拟机 Centos 7 系统中安装Nginx及Nginx支持php配置

安装Nginx

1、下载对应当前系统版本的Nginx包 (注:如果wget命令无效,请先通过yum install -y wget安装)

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2、建立Nginx的yum仓库(注:yum本身没有Nginx,建立仓库需在Nginx包所在目录)

rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

3、yum源安装Nginx

yum install -y nginx

4、防火墙设置(注: 作用域:–zone  ,添加端口(端口/协议):–add-port=80/tcp ,永久生效: -permanent )

firewall-cmd --zone=public --add-port=80/tcp --permanent

5、重启Nginx/防火墙 

systemctl restart nginx
systemctl restart firewalld

6、页面访问结果如下

安装php-fpm及php

1、先安装EPEL源用于yum源安装
yum install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 
2、yum安装php 
yum install php70w php70w-mysql php70w-fpm

Nginx支持php配置

1、修改nginx的配置文件,使其支持php文件 。(可以通过whereis nginx.conf 查找)

注意:如果在服务器上,记得将php-fpm的ww.conf中的user=apache 及group=apache 改为和nginx.conf中的user一致

location / {
    root /usr/share/nginx/html;
    # 添加index.php文件标识
    index index.html index.htm index.php;
}
location ~ \.php$ {
# html修改为php的根目录 比如: /usr/share/nginx/html
root html;

#php-fpm的默认端口是9000
fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

#/scripts修改为$document_root
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

include fastcgi_params;

}

2、重启php-fpm及Nginx 服务

systemctl restart php-fpm
systemctl restart nginx

3、验证(在php根目录下创建index.php文件,并打印出phpinfo()信息,访问验证下即可)

echo "<?php phpinfo();">>index.php

4、访问IP地址,结果如下

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值