Home  >  Article  >  php教程  >  centos+nginx+php配置简介

centos+nginx+php配置简介

WBOY
WBOYOriginal
2016-06-06 19:49:491203browse

nginx默认是不能解析PHP的,要解析PHP需要修改nginx的配置文件。 打开nginx.conf, 找到location / 修改如下: location / { root /var/www; index index.php index.html index.htm; } 找到location ~ .php$,修改如下: location ~ .php$ { root /var/www;

nginx默认是不能解析PHP的,要解析PHP需要修改nginx的配置文件。

打开nginx.conf,

找到location / 修改如下:

location / {
root   /var/www;
index  index.php index.html index.htm;
}

找到location ~ .php$,修改如下:

location ~ .php$ {
root           /var/www;
fastcgi_pass   127.0.0.1:9001;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
include        fastcgi_params;
}

root:设置PHP脚本的根目录

fastcgi_pass:处理PHP脚本的端口,这里监听9001

fastcgi_index :索引文件

fastcgi_param:php脚本路径

设置完之后,还需要配置php-fpm.conf,进入你的php安装目录下的etc文件夹,将php-fpm.conf.default重命名为php-fpm.conf,双击打开,修改listen为9001。
启动终端,cd进入php安装目录的sbin文件夹,使用./php-fpm命令启动fpm,如果启动报错,打开php-fpm.conf,去掉如下语句前的注视,然后重启php-fpm
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500

配置nginx和php-fpm开机自启动:

打开/etc/rc.local,在末尾添加

ulimit -SHn 65535
/var/web/php/sbin/php-fpm
/var/web/nginx/sbin/nginx

保存文件,重启。

注意把/var/web/php和/var/web/nginx修改成你自己的php/nginx安装目录。

在var/www目录下新建index.php,写入代码:

phpinfo();

?>

访问:http://localhost,出现php配置信息界面,大功告成!
PS:手动启动nginx,打开终端,cd进入nginx的sbin目录,使用./nginx命令启动nginx

Statement:
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