11

I have a script which is scheduled to run on crontab. I noticed that I could not see php errors anywhere. I wanted to be able to see php errors logged on /var/log/syslog or some place else. I have tried configuring my php.ini to log the errors on /var/log/php-errors.log, checked permissions and restarted the apache service still no logs.

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
madkris24
  • 483
  • 1
  • 4
  • 16
  • What did you put into the php.ini? `error_log` and `log_errors` and `error_reporting` are the Big 3 for logging to file. – Marc B Jun 24 '11 at 14:43
  • error_log = /var/log/php_errors.log, log_errors = On and error_reporting = E_ALL & ~E_DEPRECATED – madkris24 Jun 24 '11 at 14:57
  • Does the account it's running under have write permissions in /var/log and on that php-errors.log in particular? – Marc B Jun 24 '11 at 15:01
  • Im not familiar on how to check if the user has write permissions in /var/log but it does have permissions for php-errors.log – madkris24 Jun 24 '11 at 16:41

4 Answers4

10

I have this in my /etc/php5/cli/php.ini file (I use Debian; I'm assuming its the same for whatever you are using) and it writes out all cron errors to /var/log/messages:

error_reporting  =  E_ALL & ~E_NOTICE
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 0
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
error_log = syslog
Femi
  • 64,273
  • 8
  • 118
  • 148
6

Try error_log = syslog in your php.ini.

Artefact2
  • 7,516
  • 3
  • 30
  • 38
5

There are two issues to consider:

First, PHP CLI uses a different php.ini than the version of PHP that runs via Apache. Make sure you are editing the error_log in the CLI version.

Second, make sure your log file is writable by the user that runs cron. Usually the logfile is not writable by your user account, so you may need to edit permissions.

George Cummins
  • 28,485
  • 8
  • 71
  • 90
  • 5
    When logging to syslog you don't write files. The syslog daemon does. This answer doesn't make sense. – itsafire Mar 16 '15 at 07:15
2

On Ubuntu 16.04, the /dev/log is owned by group mysyslog (as defined by systemd). So for apache2/php to be able to write into syslog, you must add user www-data to group mysyslog: addgroup www-data mysyslog

Arie Skliarouk
  • 423
  • 2
  • 11