一切福田,不離方寸,從心而覓,感無不通。

centos7安装并配置nginx+php

  1. 安装nginx

    yum install nginx

  2. 设置nginx开启起动

    systemctl start nginx

  3. 测试
    访问http://你的域名或IP/
  4. 查看nginx安装位置

    whereis nginx

    nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx /usr/share/man/man3/nginx.3pm.gz /usr/share/man/man8/nginx.8.gz

  5. 安装php

    yum install php php-mysql php-fpm

    安装过程中经常会见到如下问题:
    2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18()(64bit)
    2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18(libmysqlclient_18)(64bit)
    解决方法:
    把php-mysql换成php-mysqlnd
    即执行

    yum install php php-mysqlnd php-fpm

  6. 配置php处理器

    vim /etc/php.ini

    查找cgi.fix_pathinfo
    将 ;cgi.fix_pathinfo=1改为cgi.fix_pathinfo=0

  7. 配置www.conf

    vim /etc/php-fpm.d/www.conf


    user = nobody
    group = nobody
    改为
    user = nginx
    group = nginx
    前提是已经创建了nginx用户和nginx组。

  8. 起动php-fpm

    systemctl start php-fpm

  9. 设置php-fpm开机启动

    systemctl enable php-fpm

  10. 配置nginx
    打开/etc/nginx/conf.d/default.conf,如果不存在则创建
    粘贴
    server {
    listen 80;
    server_name server_domain_name_or_IP;

    note that these lines are originally from the "location /" block

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
    try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /usr/share/nginx/html;
    }

    location ~ .php$ {
    try_files $uri =404;
    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.conf;
    }
    }

  11. 重起nginx

    systemctl restart nginx

  12. 测试php
    创建/usr/share/nginx/html/index.php

    /usr/share/nginx/html/info.php

    输入以下内容:

访问http://你的IP/index.php,正常情况下会出现

 

from:https://www.cnblogs.com/cglWorkBook/p/5431571.html