centos下配置nginx支持php的方法

发布时间:2020-05-13编辑:脚本学堂
本文介绍了centos系统中配置nginx支持php的操作方法,有需要的朋友参考下。

安装php:
 

复制代码 代码示例:
yum install php
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

添加nginx 默认主页index.php
vim /etc/nginx/conf.d/default.conf
 

复制代码 代码示例:
location / {
   root   /usr/share/nginx/html;
   index  index.html index.htm index.php;
}

配置nginx支持php
vim /etc/nginx/conf.d/default.conf
 

复制代码 代码示例:
# pass the PHP scripts to fastcgi server listening on 127.0.0.1:9000
#
location ~ .php$ {
   root           html;
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_index  index.php;
   fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
   include        fastcgi_params;
}
 

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

复制代码 代码示例:
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

后续工作: 
 

复制代码 代码示例:
chkconfig php-fpm on    #设置php-fpm自启动
chkconfig mysqld on     #设置mysqld自启动
service nginx restart   #重新启动nginx
service php-fpm start   #启动php-fpm
service mysqld start    #启动mysqld