红联Linux门户
Linux帮助

CentOS 6部署Nginx+PHP5服务器

发布时间:2015-04-19 15:33:05来源:linux网站作者:BORO

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

可以参考 PHP 官方文档:http://php.net/manual/zh/install.unix.nginx.php


安装一些必要的 YUM 库

root 用户执行:
# rpm -Uvh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm


安装 Nginx

添加 nginx 的 YUM 库配置文件 /etc/yum.repos.d/nginx.repo,
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/CentOS/$releasever/$basearch/
gpgcheck=0
enabled=1

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 的时候

文章:http://blog.martinfjordvald.com/2011/01/no-input-file-specified-with-php-and-nginx/

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