PHP内置服务器错误日志位置

时间:2021-11-04 00:09:39

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.

我不知道有没有?但是内置在Web服务器中的PHP也将其错误日志保存在文件中吗?用于拖尾目的,例如在apache中创建虚拟主机时。

UPDATE: i'm using mac osx

更新:我正在使用mac osx

5 个解决方案

#1


5  

Yes, PHP has built in error log functionality.

是的,PHP内置了错误日志功能。

PHP logs errors to this file automatically.

PHP会自动将错误记录到此文件中。

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

如果要记录错误,请使用函数error_log()

The file's location changes depending upon enviroment.

文件的位置根据环境而变化。

e.g.

in Ubuntu 12.04, its

在Ubuntu 12.04中,它的

var/log/php_errors.log

In XAMPP windows,

在XAMPP窗口中,

\xampp\php\logs\php_errors.log

In Mac OS,

在Mac OS中,

/var/log/apache2/php_errors.log

#2


15  

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:

默认情况下,内置的Web服务器不会记录任何位置,因此您需要提供一个php.ini来自定义它。例如,如果您使用以下内容创建了一个名为php.ini的文件:

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

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

然后你可以像这样启动PHP的内置网络服务器:

php -S 127.0.0.1:8080 -c php.ini

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

并且error_log()调用将记录到您指定的文件中。

#3


1  

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

在macOS上使用PHP内置服务器时,需要在php.ini配置文件(php -i | grep php.ini)中指定error_log。

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

如果您决定使用syslog(而不是日志文件),例如:

error_log = syslog

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

然后要转储日志,您可以在macOS上使用log命令,例如

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).

否则,请使用错误日志的某些特定文件路径(例如/usr/local/var/log/php-error.log)。

#4


0  

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

要更新Mac OS X High Sierra(10.13.5):这对我有用,无需更改任何PHP默认值。只是用

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

and tail the error log:

并拖尾错误日志:

tail -f /var/log/apache2/error_log

#5


-2  

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

如果您使用的是Mac OS或Ubuntu,则可以轻松查看错误日志

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

#1


5  

Yes, PHP has built in error log functionality.

是的,PHP内置了错误日志功能。

PHP logs errors to this file automatically.

PHP会自动将错误记录到此文件中。

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

如果要记录错误,请使用函数error_log()

The file's location changes depending upon enviroment.

文件的位置根据环境而变化。

e.g.

in Ubuntu 12.04, its

在Ubuntu 12.04中,它的

var/log/php_errors.log

In XAMPP windows,

在XAMPP窗口中,

\xampp\php\logs\php_errors.log

In Mac OS,

在Mac OS中,

/var/log/apache2/php_errors.log

#2


15  

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:

默认情况下,内置的Web服务器不会记录任何位置,因此您需要提供一个php.ini来自定义它。例如,如果您使用以下内容创建了一个名为php.ini的文件:

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

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

然后你可以像这样启动PHP的内置网络服务器:

php -S 127.0.0.1:8080 -c php.ini

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

并且error_log()调用将记录到您指定的文件中。

#3


1  

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

在macOS上使用PHP内置服务器时,需要在php.ini配置文件(php -i | grep php.ini)中指定error_log。

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

如果您决定使用syslog(而不是日志文件),例如:

error_log = syslog

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

然后要转储日志,您可以在macOS上使用log命令,例如

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).

否则,请使用错误日志的某些特定文件路径(例如/usr/local/var/log/php-error.log)。

#4


0  

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

要更新Mac OS X High Sierra(10.13.5):这对我有用,无需更改任何PHP默认值。只是用

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

and tail the error log:

并拖尾错误日志:

tail -f /var/log/apache2/error_log

#5


-2  

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

如果您使用的是Mac OS或Ubuntu,则可以轻松查看错误日志

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