发现php 运行错误时,浏览器的网页上并没有输出php的错误日志。那php的错误日志在哪里呢? 发现在 /var/log/nginx/error.log文件中。

怎么样才能在浏览器的网页中输出php的出错信息呢?
编辑 /etc/php5/fpm/php.ini文件,将display_errors = On. (如果不改php.ini文件,只是在执行文件中 ini_set("display_errors", "on"))发现没效果,不知道为什么呢?奇怪!!

这样改了php.ini文件后,网页上就可以看到php的出错信息了,便于调试。

-------------------------------------------------------------------------------------------------
|
I gathered insights from a bunch of answers here and I present a comprehensive solution:
So, if you setup nginx with php5-fpm and log a message using error_log() you can see it in /var/log/nginx/error.log by default.
A problem can arise if you want to log a lot of data (say an array) using error_log(print_r($myArr, true)); . If an array is large enough, it seems that nginx will truncate your log entry.
To get around this you can configure fpm to manage logs. Here are the steps to do so.
-
Open /etc/php5/fpm/pool.d/www.conf :
$ sudo nano /etc/php5/fpm/pool.d/www.conf
-
Uncomment the following two lines by removing ; at the beginning of the line:
;php_admin_value[error_log] = /var/log/fpm-php.www.log ;php_admin_flag[log_errors] = on
-
Create /var/log/fpm-php.www.log :
$ sudo touch /var/log/fpm-php.www.log;
-
Change ownership of /var/log/fpm-php.www.log so that php5-fpm can edit it:
$ sudo chown vagrant /var/log/fpm-php.www.log
Note: vagrant is the user that I need to give ownership to. You can see what user this should be for you by running $ ps aux | grep php.*www and looking at first column.
-
Restart php5-fpm:
$ sudo service php5-fpm restart
Now your logs will be in /var/log/fpm-php.www.log .
|
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
2015-12-25 FastCgi与PHP-fpm之间是个什么样的关系