思:因为在源码安装nginx+php的时候遇到一些卡壳的地方,在此做个记录,全无技术含量!
【安装配置php-fpm】
版本:php-5.5.16
进入源码目录
./configure --prefix=/home/work/php --enable-fastcgi --enable-fpm
make -j 16
make install
从源码目录拷贝php.ini到/home/work/etc下。
cp php.ini-producument /home/work/php/etc/php.ini
(1).root帐户
为什么要拿root帐户来讲,因为一开始我第一次配置的时候没有注意到帐户问题,直接按默认配置启动php-fpm,但不能正常工作,检查nginx出错日志找到类似如下信息:
[root@localhost logs]# cat error.log
2015/11/10 15:17:29 [error] 1078#0: *8 FastCGI sent in stderr: "Primary script unknown" while reading response header from
upstream, client: 172.22.223.121, server: , request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:54321", host:
"10.115.122.49"
在确认nginx配置OK后发现是php-fpm帐户的问题,默认是用的nobody。
php-fpm默认情况下禁用了root帐户启动,参见其help输出信息:
Usage: php-fpm [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y <file>] [-D] [-F]
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-h This help
-i PHP information
-m Show compiled in modules
-v Version number
-p, --prefix <dir>
Specify alternative prefix path to FastCGI process manager (default: /root/http/php).
-g, --pid <file>
Specify the PID file location.
-y, --fpm-config <file>
Specify alternative path to FastCGI process manager config file.
-t, --test Test FPM configuration and exit
-D, --daemonize force to run in background, and ignore daemonize option from config file
-F, --nodaemonize
force to stay in foreground, and ignore daemonize option from config file
-R, --allow-to-run-as-root
Allow pool to run as root (disabled by default)
如果坚持使用root帐户的话,启动参数需要加上-R。并对php-fpm.conf配置文件进行修改:
vim etc/php-fpm.conf
...
[www]
user = root
group = root
....
另外,当然还要配置php-fpm和nginx通信的ip和端口:
vim etc/php-fpm.conf
...
listen = 127.0.0.1:54321 #用于和nginx通信
....
然后就可以正常启动了。
[root@localhost php]./sbin/php-fpm -y etc/php-fpm.conf -c etc/php.ini -R
(2).非root帐户
[root@localhost php]./sbin/php-fpm -y etc/php-fpm.conf -c etc/php.ini
【安装配置nginx】
似乎无需多言,只需贴上一份nginx的参考配置:
user root;
worker_processes 6;
error_log logs/error.log;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
location / {
root html;
index index.html index.htm index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:54321;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}