CentOS 6部署Nginx + PHP5 服务器

在 CetnOS 6 (64位) 操作系统上部署Nginx and PHP5服务器。这个过程通过 yum 命令进行RPM包安装。

可以参考 PHP 官方文档

安装 一些必要的 YUM 库

安装 Nginx

root 用户执行:
# yum install nginx

安装 PHP 及重要插件 php-fpm

root 用户执行:
# yum install php-fpm php

配置、启动 php-fpm

配置 /etc/php.ini:
# 找到并取消注释,设置成:
cgi.fix_pathinfo=0

配置 /etc/php-fpm.d/www.conf:
# 找到并取消注释,设置成你希望管理 www 应用的用户(我这里统一用用户 theflash)
listen.owner = theflash
listen.group = theflash

启动 php-fpm 监听服务
# service php-fpm start

停止 php-fpm 监听服务
# service php-fpm stop

配置、启动 Nginx

创建一个网站根目录 /data/wwwroot,并更换目录所有者为 theflash。  root 用户执行
# mkdir -p /data/wwwroot
# chown theflash:theflash /data/wwwroot -R

从此,以后就用用户 theflash 来登录并维护 /data/wwwroot 中的数据

直接分享我的配置 /etc/nginx/nginx.conf:
user theflash;

events {
}

http {
    include    /etc/nginx/mime.types;
    server {
        root    /data/wwwroot;

        location / {
            index  index.html index.htm index.php;
        }

        error_page  404              /404.html;

        location ~* \.php$ {
            fastcgi_index  index.php;
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

启动 Nginx 服务器
# service nginx start

停止 Nginx 服务器
# service nginx stop

如果运行时修改了配置文件,需要重新加载 Nginx 服务器配置文件,而不需要停止 Nginx 服务器
# nginx -s reload

FAQ

如何解决 “NO INPUT FILE SPECIFIED” 的问题,当我们安装 PHP 和 NGINX 的时候

文章: 英文原版

检查 php 文件是否拥有写权限,它的父目录都有执行权限 ?
#<-- container folders should be granted execute permission
chmod a+x /data
chmod a+x /data/wwwroot

--------------------------------------分割线 --------------------------------------

Nginx 的详细介绍请点这里
Nginx 的下载地址请点这里

猜你喜欢

转载自www.linuxidc.com/Linux/2015-03/115250.htm