按照前两篇文章编译安装了Nginx和PHP,这里介绍配置Nginx和PHP, 实现两者互通。
一、配置PHP
0、清理php-fpm.conf中的注释, 只保留最后一行(本身有php-fpm.conf.default文件,不要担心备份)
tail -n 1 /usr/local/php/etc/php-fpm.conf
# 显示内容 include=/usr/local/php/etc/php-fpm.d/*.conf
echo 'include=/usr/local/php/etc/php-fpm.d/*.conf' > /usr/local/php/etc/php-fpm.conf
1、清空www.conf, 写入以下简洁内容
echo '' > /usr/local/php/etc/php-fpm.d/www.conf
# copy以下内容到www.conf中
[www]
user = www
group = www
listen = 127.0.0.1:9000
listen.owner = www
listen.group = www
listen.mode = 0660
listen.allowed_clients = 127.0.0.1
pm = dynamic
listen.backlog = -1
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 5
request_terminate_timeout = 120
request_slowlog_timeout = 50
slowlog = var/log/slow.log
3、启动或重启PHP-FPM服务
/etc/init.d/php-fpm reload
4、查看端口
netstat -anlp | grep '9000'
能查看到php-fpm在监听9000端口,表明配置正常。否则请检查php-fpm服务状态以及查看php-fpm错误日志。
二、配置Nginx
0、配置nginx.conf,修改server块内容如下
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
root /var/www/html/test;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/test$fastcgi_script_name;
include fastcgi_params;
}
}
1、启动或重启Nginx
/etc/init.c/nginx reload
启动正常,表明配置正常。否则请根据错误提示或者查看错误日志排查。
三、测试验证
0、新建测试脚本index.php
mkdir -p /var/www/html/test
touch /var/www/html/test/index.php
1、写入PHP测试代码
phpinfo();
// the end of the script
2、浏览器请求服务器IP
看到phpinfo页面信息,表明配置成功。
这里介绍的只是基本配置,让两者快速的互通起来,优化的配置参考后面的文章。
(全文完)