PHP错误不存储在CentOS服务器上

我只是调整了/etc/php.ini中的CentOS 64位VPS上的php.ini来loggingPHP错误:

cat /etc/php.ini | grep php-errors.log error_log = /var/log/php-errors.log 

我也有log_errors = on

我在/ var / log /中创build了日志文件,它是CHMOD 644.我也打开了错误报告E_ALL

 cat /etc/php.ini | grep error_reporting ; error_reporting error_reporting = E_ALL ; Eval the expression with current error_reporting(). Set to true if you want ; error_reporting(0) around the eval(). 

然后我重新启动了httpd守护进程。 当我通过WordPress上传器添加文件时,我看到它没有被上传,因为权限问题

 “cannot-open-file.png” has failed to upload due to an error Unable to create directory wp-content/uploads/2014/05. Is its parent directory writable by the server? 

,但它不会在php-errors.php中存储为错误:

 pwd /var/log ls -l | grep php -rw-r--r-- 1 root root 0 May 6 06:21 php-errors.log 

我在/var/log/httpd中的所有其他日志也是root:root所以我会假定日志会工作。 而当我没有调整文件的权限到apache:apachebuild议我仍然没有在日志文件中的错误。 即使将错误日志logging添加到.htaccess也没有帮助。

我也使用phpinfo()检查了PHP.ini。 唯一加载的是我在/etc/php.ini调整的,并且它使用的用户和组是apache – User/Group apache(48)/48 。 我错过了什么?

PS可能是在这里build议的日志文件的目录问题不能configurationPHP错误日志我正在检查更多的信息。

如果您在编写/读取文件时遇到困难,您应该查看此答案中的详尽列表: https : //stackoverflow.com/questions/12531408/setting-php-tmp-dir-php-upload-not-working

基本上,如果你希望apache写入一个不是syslog的error_log文件,apache需要有权写入它,如果文件不存在,apache也需要在父文件夹上写入权限。

但是,如果您尝试读/写或者将您的error_log设置为从CentOS 7开始的/ tmp文件夹,则这些都不适用。 答案在这里: https : //stackoverflow.com/questions/10752396/cant-write-to-tmp-with-php-despite-777-permissions-and-no-open-basedir-value?rq=1引用这个博客http://blog.oddbit.com/2012/11/05/fedora-private-tmp/解释systemd是如何不允许的。

从官方文档中 ,您应该更改/var/log/php-errors.log的权限,以便apache用户可以写入文件(例如www,www-data等)

 #chown www:www 

error_logstring

应logging脚本错误的文件的名称。 该文件应该可以由Web服务器的用户写入。 如果使用特殊值syslog,那么错误将被发送到系统logging器。 在Unix上,这意味着系统日志(3),在Windows NT上它意味着事件日志。 系统logging器在Windows 95上不受支持。另请参阅:syslog()。 如果未设置此指令,则将错误发送到SAPI错误logging器。 例如,它是Apache中的错误日志或CLI中的stderr。 另请参见error_log()。

显然我还需要display_errors = on 。 我认为这是为了在屏幕上显示错误,但它也是错误logging。