php PHP内置服务器错误日志位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27122267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP built-in server error log location
提问by Bryan Estrito
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
回答by thenickdude
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:
默认情况下,内置的网络服务器不会在任何地方登录,因此您需要为其提供一个 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() 调用将记录到您指定的文件中。
回答by Pupil
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
var/log/php_errors.log
In XAMPP windows,
在 XAMPP 窗口中,
\xampp\php\logs\php_errors.log
\xampp\php\logs\php_errors.log
In Mac OS,
在 Mac 操作系统中,
/var/log/apache2/php_errors.log
/var/log/apache2/php_errors.log
回答by kenorb
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 内置服务器时,您需要error_log
在php.ini
配置文件 ( php -i | grep php.ini
) 中指定。
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.
然后转储日志,您可以log
在 macOS 上使用命令,例如
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
)。
回答by dhc
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
回答by 3lit3h4XX0r666
I primarily know linux but AFAIK this works the same on whatever sytem you can run php. I recently spent an unreasonable amount of time getting linux to run on a "obsolete" macmini from 2009. I don't know how anyone tolerates that manufactured obsolescence. Android is just is bad, hiding behind that "based on linux" nonsense. I wonder how many lawyers it took to figure that one out? Of course, GPL doesn't say anything about the hardware! Thanks to them, when mobile devices inevitably replace laptops and desktops over the next decade, the threat of the ideas behind free software will have been mostly eliminated. They should put that kind of engineeringto work in consumer smoke alarm technology..
我主要了解 linux,但 AFAIK 这在任何你可以运行 php 的系统上都是一样的。我最近花了不合理的时间让 linux 在 2009 年的“过时”macmini 上运行。我不知道有人如何容忍这种制造过时的情况。Android 就是很糟糕,背后隐藏着“基于 linux”的废话。我想知道需要多少律师才能解决这个问题?当然,GPL 对硬件没有任何说明!多亏了他们,当未来十年移动设备不可避免地取代笔记本电脑和台式机时,自由软件背后的思想威胁将基本消除。他们应该将这种工程应用于消费者烟雾报警技术。.
Anyway, enough about that. I'll attempt to return to topic and teach you how to do this in a way that will give you the tools to complete similar different tasks in the future. It's like that old saying goes, "Teach a man to fish and won't be able to sell him anymore fish"
无论如何,足够了。我将尝试回到主题并教您如何以一种为您提供工具来完成未来类似不同任务的方式来执行此操作。俗话说“授人以渔,鱼卖不去”
I always like to begin with a man [command]
or [command] --help
if --help
or -h
doesn't work, try to pass it invalid input, that will usually get it talking. Be careful at this step, it's easy to get stuck reading man pages for several hours, try not to forget any time obligations you might be under.
我总是喜欢以 a man [command]
or [command] --help
if --help
or -h
not work开头,尝试将无效输入传递给它,这通常会让它说话。在这一步要小心,很容易在几个小时内阅读手册页卡住,尽量不要忘记你可能承担的任何时间义务。
php --help
Find the option to set ini variables:
找到设置ini变量的选项:
-d foo[=bar] Define INI entry foo with value 'bar'
Reading an example php.ini
we find the settings of interest.
阅读一个例子,php.ini
我们找到了感兴趣的设置。
; error_reporting
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
///
; Log errors to specified file. PHP's default behavior is to leave this value
; empty.
; http://php.net/error-log
; Example:
;error_log = php_errors.log
; Log errors to syslog (Event Log on Windows).
;error_log = syslog
all the other defaults look ok so... let's try:
所有其他默认值看起来都不错,所以......让我们尝试:
php -d error_reporting=E_ALL -d error_log=/desired/path/to/error.log -S 0.0.0.0:9999
You might notice the log printing to stderr
from here. Alternatively, you could redirect thatby adding 2> /path/to/error.log
to the end of the above command. Simpler, but then you wouldn't have learned about -d
options to set values from php.ini and -c
to use a custom file, but you'd have learned about output redirection which i'd say is a far more important concept with countless applications.
您可能会注意到stderr
从这里打印的日志。或者,您可以通过添加2> /path/to/error.log
到上述命令的末尾来重定向它。更简单,但是您不会了解-d
从 php.ini 设置值和-c
使用自定义文件的选项,但您会了解输出重定向,我认为这是一个更重要的概念,适用于无数应用程序。
回答by Balaji.J.B
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