3

I just adjusted the php.ini on my CentOS 64 Bits VPS in /etc/php.ini to log PHP errors:

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

I also have log_errors = on

I created the log file in /var/log/ and it is CHMOD 644. I also turned on Error reporting 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().

Then I restarted the httpd daemon. When I add a file via the WordPress uploader I see it is not uploaded because of a permission issue

“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?

, but it is not stored as an error in php-errors.php:

pwd
/var/log

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

All my other logs in /var/log/httpd are also root:root so I would assume the logging would work. And when I did adjust the file's permissions to apache:apache as suggested I still had no errors in the log file. Even adding error logging on to the .htaccess did not help.

I also checked the PHP.ini using phpinfo() . The only ini loaded is the one I adjusted in /etc/php.ini and the user and group it is using is apache - User/Group apache(48)/48 . What am I missing?

PS Could be issues with the directory for the log files as suggested here Can't configure PHP error log I am checking out more info on this.

rhand
  • 264
  • 2
  • 5
  • 23
  • Apparently I also needed `display_errors = on` . I thought this was for error display onscreen but it is for error logging as well it seems. Will add this as final solution unless someone can explain this better. In that case I will be more than happy to mark that answer as the solution – rhand May 06 '14 at 07:48

4 Answers4

4

From official documentation, you should change permission of /var/log/php-errors.log so the file is writable by apache user (e.g www, www-data, etc.)

#chown www:www 

error_log string

Name of the file where script errors should be logged. The file should be writable by the web server's user. If the special value syslog is used, the errors are sent to the system logger instead. On Unix, this means syslog(3) and on Windows NT it means the event log. The system logger is not supported on Windows 95. See also: syslog(). If this directive is not set, errors are sent to the SAPI error logger. For example, it is an error log in Apache or stderr in CLI. See also error_log().

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
  • Adjusted permissions and recreated same error by trying to upload a file. php error file is still empty:`ls -l | grep php -rw-r--r-- 1 apache apache 0 May 6 06:21 php-errors.log` – rhand May 06 '14 at 03:23
  • Check output of phpinfo(). Maybe these paramater was overridden somewhere. – masegaloeh May 06 '14 at 03:55
3

If you are having trouble writing/reading files you should review the exhaustive list in this answer: https://stackoverflow.com/questions/12531408/setting-php-tmp-dir-php-upload-not-working

Basically, if you want apache to write to a an error_log file other than syslog, apache needs to have permissions to write to it, and if the file does not yet exist apache needs write permissions on parent folder as well.

None of this applies if you are trying to read/write or set your error_log to the /tmp folder starting in CentOS 7 however. The answer here: https://stackoverflow.com/questions/10752396/cant-write-to-tmp-with-php-despite-777-permissions-and-no-open-basedir-value?rq=1 Referencing this blog http://blog.oddbit.com/2012/11/05/fedora-private-tmp/ explains how systemd does not allow it.

im3r3k
  • 141
  • 5
1

Apparently I also needed display_errors = on . I thought this was for error display onscreen but it is for error logging as well it seems.

rhand
  • 264
  • 2
  • 5
  • 23
-1

When running # ls -la /var/log/php-fpm, you will see a file called error.log and another file called www-error.log. Simply use that file.

It's under Centos 8, PHP 7.4 FPM.

Paul
  • 3,037
  • 6
  • 27
  • 40
Rudra
  • 1