我在 Ubuntu 14.04 机器上使用 php-fpm 5.5.9 和 nginx 1.4.6。我使用 apt-get 包管理器安装了它们。我无法在错误日志和浏览器中获取 index.php 脚本遇到的错误的堆栈跟踪。我从 stackoverflow 和其他文章中搜索并实施了几个解决方案,但没有一个对我有用。这是我的 nginx conf 以及我的 php-fpm conf 文件。如果我犯了任何愚蠢的错误,请帮助我。
Nginx 配置:
location ~ \.php$ {
# With php5-fpm:
#try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_read_timeout 600;
fastcgi_send_timeout 600;
proxy_connect_timeout 600;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
fastcgi_pass 127.0.0.1:7777;
fastcgi_index index.php;
}
PHP-FPM配置:
error_log = /tmp/php5-fpm.log
PHP-FPM 池配置:
catch_workers_output = yes
slowlog = /var/log/php-fpm/$pool.log.slow
listen = 127.0.0.1:7777
php_flag[display_errors] = On
php_admin_value[error_log] = /tmp/fpm-php.www.log
php_admin_flag[log_errors] = On
提前致谢。
答案1
尝试在服务器指令中输入以下内容到站点的配置中:
access_log /var/log/nginx/your_site.log;
error_log /var/log/nginx/your_site.log;
your_site.log
用您的虚拟主机名称(域名)替换。
完整示例:
php-fpm
/etc/php5/fpm/php-fpm.conf
[global]
pid = /var/run/php5-fpm.pid
error_log = /var/log/php5-fpm.log
include=/etc/php5/fpm/pool.d/*.conf
/etc/php5/fpm/pool.d
[www]
user = www-data
group = www-data
pm = dynamic
pm.max_children = 10
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
虚拟主机
upstream php {
server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}
server {
listen 80; ## listen for ipv4; this line is default and implied
root /srv/www/mysite;
index index.php;
server_name mysite.com www.mysite.com;
access_log /var/log/nginx/mysite_access.log;
error_log /var/log/nginx/mysite_error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9$
location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
access_log off;
log_not_found off;
}
}
答案2
如果您想要脚本的执行错误,可以在 上进行配置/etc/php5/fpm/php.ini
。
如果您希望日志文件中出现错误,请编辑php.ini
:
display_errors = off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
error_log = /path/to/some/file.log
如果您希望它们在浏览器上使用,请编辑php.ini
:
display_errors = on
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
或者,将其添加到脚本顶部:
ini_set('display_errors',1);
error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT );
我不知道如何直接在日志文件中记录堆栈跟踪,但是这里有一种方法可以实现定义自己的错误处理程序。