PHP built-in server error log location

2019-02-21 10:25发布

问题:

I don't know if there's any? but is php built in web server also save its error logs in a file? for tailing purposes, like when creating virtual host in apache.

UPDATE: i'm using mac osx

回答1:

Yes, PHP has built in error log functionality.

PHP logs errors to this file automatically.

If you want to log errors, use the function error_log()

The file's location changes depending upon enviroment.

e.g.

in Ubuntu 12.04, its

var/log/php_errors.log

In XAMPP windows,

\xampp\php\logs\php_errors.log

In Mac OS,

/var/log/apache2/php_errors.log



回答2:

The built-in webserver doesn't log anywhere by default, so you need to provide a php.ini for it to customise this. For example, if you created a file called php.ini with this content:

error_log = /Users/me/test.log
log_errors = on
date.timezone = UTC

Then you can start PHP's built-in webserver like this:

php -S 127.0.0.1:8080 -c php.ini

And error_log() calls will be logged to the file you've specified.



回答3:

When using PHP builtin server on macOS, you need to specify error_log in your php.ini config file (php -i | grep php.ini).

If you decide with syslog (instead of a log file) such as:

error_log = syslog

Then to dump the logs, you can use log command on macOS, e.g.

log stream --predicate 'processImagePath contains "php"'

Otherwise use some specific file path for the error log (e.g. /usr/local/var/log/php-error.log).



回答4:

To update for Mac OS X High Sierra (10.13.5): this worked for me with no need to change any PHP defaults. Just use

error_log('*** notice this***');

and tail the error log:

tail -f /var/log/apache2/error_log


回答5:

If you are using Mac OS or Ubuntu, this the way you can easily look into the error log

tail -f /var/log/apache2/error_log

this will give you error log in realtime or you can use , which will give last error logs

tail /var/log/apache2/error_log