centos7 nginx+php7yum安装

centos7 nginx+php7yum安装。

1.安装yum源

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

2.安装nginx

yum install -y nginx

3.启动nginx并设置开机自动运行

  1. systemctl start nginx #启动,restart-重启,stop-停止

  2. systemctl enable nginx #开机启动

4.查看版本及运行状态

  1. nginx -v #查看版本

  2. ps -ef | grep nginx #查看运行状态

二.安装php7

1.安装yum源

  1. rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

  2. rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2.查看php7 yum组件,示例安装php7.2

  1. yum search php72w

3.选择自己需要的组件安装,php72w.x86_64 和 php72w-fpm.x86_64 为核心程序必装

yum install php72w.x86_64 php72w-fpm.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-mcrypt.x86_64 php72w-mysql.x86_64 php72w-pdo.x86_64 php72w-pecl-redis.x86_64

4.启动php并设为开机启动

  1. systemctl start php-fpm #启动,restart-重启,stop-停止

  2. systemctl enable php-fpm #开机启动

5.查看版本及运行状态

  1. php-fpm -v #查看版本

  2. ps -ef | grep php-fpm #查看运行状态


进行完以上步骤之后,读者自行在nginx中配置web目录,已经可以正常运行了,但是此时nginx和php是以root身份运行,以最高权限运行web文件会给系统带来安全隐患,以下为权限配置示例


三.修改nginx配置

  vi /etc/nginx/conf.d/default.conf

  1. 找到第一个location中的这一行

    index index.html index.htm;

    修改为:

    index index.php index.html index.htm; #添加index.php

2.

    把FastCGI server这行下面的location的注释去掉,并修改成下面这样子

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    location ~ \.php$ {

    root /usr/share/nginx/html; #网站根目录

    fastcgi_pass 127.0.0.1:9000;

     fastcgi_index index.php;

     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

     include fastcgi_params;

     }

service nginx restart #重启nginx

service php-fpm start #开启php-fpm

  3.

在网站根目录新建index.php文件

vim /usr/share/nginx/html/index.php

  4.

输入内容:

<?php

phpinfo();

  5.

在浏览器中输入虚拟机ip,已经可以看到phpinfo的信息了

在windows上修改hosts文件,添加一行

192.168.6.114 www.test1.com #配置虚拟机ip对应域名

  6.

现在就可以在windows上用www.test1.com访问虚拟机配置的服务器了