Home > Backend Development > PHP Tutorial > CentOS 6 部署 Nginx + PHP5 服务器

CentOS 6 部署 Nginx + PHP5 服务器

WBOY
Release: 2016-06-23 13:38:21
Original
1205 people have browsed it

CentOS 6 部署 Nginx + PHP5 Web服务器

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

可以参考 PHP 官方文档。

安装 一些必要的 YUM 库

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmrpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
Copy after login

安装 Nginx

添加 nginx 的 YUM 库配置文件 /etc/yum.repos.d/nginx.repo

[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1
Copy after login

root 用户执行:

# yum install nginx
Copy after login

安装 PHP 及重要插件 php-fpm

root 用户执行:

# yum install php-fpm
Copy after login

将会安装好 php-fpm 以及 php 本身在内的其他依赖。

配置、启动 php-fpm

配置 /etc/php.ini,设置 cgi.fix_pathinfo=0

启动 php-fpm 并放置后台运行

php-fpm -D
Copy after login

停掉 php-fpm 的方法

root@acx-xiwang:/etc# ps -ef | grep php-fpmroot     31591     1  0 14:09 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)apache   31592 31591  0 14:09 ?        00:00:00 php-fpm: pool wwwapache   31593 31591  0 14:09 ?        00:00:00 php-fpm: pool wwwapache   31594 31591  0 14:09 ?        00:00:00 php-fpm: pool wwwapache   31595 31591  0 14:09 ?        00:00:00 php-fpm: pool wwwapache   31596 31591  0 14:09 ?        00:00:00 php-fpm: pool wwwroot     31914 31878  0 14:32 pts/1    00:00:00 grep --color php-fpmroot@acx-xiwang:/etc# kill -s SIGINT 31591
Copy after login

或者通过 service 命令执行

service php-fpm stopservice php-fpm start
Copy after login

配置、启动 Nginx

直接分享我的配置 /etc/nginx/nginx.conf

user xiwang;events {}http {    include     /etc/nginx/mime.types;    server {        root    /home/xiwang/opt/www;        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;            fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;            include         fastcgi_params;        }    }}
Copy after login

启动 Nginx 服务器

$ nginx
Copy after login

或者通过 service 命令执行:

service nginx stopservice nginx start
Copy after login

如果运行时修改了配置文件,可以通过 nginx -s reload 来使配置文件生效。

FAQ

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

文章: 英文原版

检查 php 文件是否拥有写权限,它的父目录都有执行权限

chmod a+x /home/xiwang/opt            #<-- container folder should be granted execute permissionchmod a+x /home/xiwang/opt/www        #<-- container folder should be granted execute permissionchmod a+w /home/xiwang/opt/www/*.php  #<-- .php file should be granted write permission
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template