Reputation: 2686
I develop a local script quick & dirty and let it run on the command line. I have no server installed.
My php ini lies at /usr/local/etc/php/7.4/php.ini
I activated the error log by using
error_reporting = E_ALL
display_errors = On
log_errors = On
error_log = /var/log/php_errors.log
I saved the changes but don't find a log written at /var/log/php_errors.log
What do I have to do to get my errors logged in a file?
Output of
$ php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File: /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.4/conf.d/ext-opcache.ini
$ which php
/usr/local/bin/php
Upvotes: 2
Views: 896
Reputation: 59
My understanding is that the php cli outputs errors to the command line in much the same way as a bash script. Therefore you can output your errors to your own log file in the same way.
Here is a simple script file error_test.php
which which has two commands. First echoes a string - second echoes an undefined variable which will create an error:
<?php
echo "hello\n";
echo $test;
run the script as
php error_test.php
and it will output the following:
hello
PHP Notice: Undefined variable: test in /home/phi/Projects/sandbox/error_test.php on line 3
Like a bash script, we can redirect the stderr output to a file with 2>
php error_test.php 2> error.log
cat error.log
This replaces the log file each time the command is run. To append the errors to the log file use 2>>
.
php error_test.php 2>> error.log
To ignore errors, redirect to /dev/null
php error_test.php 2>> /dev/null
Upvotes: 0