How to set error log for PHP CLI?

I have a php script that works fine with Apache, but it does not work when working in cli, so I want to know what is happening. For this, I would like to see the error log, but the cli error log I installed does not work. I installed this in the corresponding php.ini file, which is confirmed when I get the error log data via the command line:

$ php -i | grep error display_errors => Off => Off display_startup_errors => Off => Off error_append_string => no value => no value error_log => /var/log/php_error_log => /var/log/php_error_log error_prepend_string => <font color=ff0000> => <font color=ff0000> error_reporting => 30711 => 30711 html_errors => Off => Off ignore_repeated_errors => Off => Off log_errors => On => On log_errors_max_len => 1024 => 1024 track_errors => Off => Off xmlrpc_error_number => 0 => 0 xmlrpc_errors => Off => Off suhosin.disable.display_errors => Off => Off suhosin.sql.bailout_on_error => Off => Off 

So, error_log and log_errors both set. Hover over no logs actually saved. There are permissions. So what could it be? I read this topic: PHP CLI will not log errors , but could not find a solution here.

+4
source share
2 answers

PHP through the CLI and HTTP request use a different php.ini configuration. In your case, I suspect if you are dealing with php.ini used by the PHP CLI. Can you try to do:

 $ php -i >> info.txt 

This will save your phpinfo () in the local info.txt file. Then open the file and find the parameter " Loaded configuration file "), which should indicate the absolute path to the downloaded php.ini file.

If everything is ok, just run the CLI command to check if the error_log function works as expected. Run through CLI:

 $ php -r "error_log('test error', 3, './errors.log')" 

and you should find in the same errors.log directory file with the specified test error. If you cannot find it, you will probably need to update your php.ini settings or set the correct write, process or file permissions.

+6
source

The log file is probably already created by php (mod_php or php_fpm, etc.) with another user (www-data?). Therefore, if you run your script like anyone else, it may not have write permissions to the file or it may not even have access to this path. You can try running it as another user.

 sudo -u www-data php your_script.php 
+1
source

Source: https://habr.com/ru/post/1392231/


All Articles