Linux 每个虚拟主机的 error_log?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/176/
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
error_log per Virtual Host?
提问by Michael Stum
On one Linux Server running Apache and PHP 5, we have multiple Virtual Hosts with separate log files. We cannot seem to separate the php error_logbetween virtual hosts.
在一台运行 Apache 和 PHP 5 的 Linux 服务器上,我们有多个带有单独日志文件的虚拟主机。我们似乎无法error_log在虚拟主机之间分离 php 。
Overriding this setting in the <Location>of the httpd.confdoes not seem to do anything.
在 的<Location>中覆盖此设置httpd.conf似乎没有任何作用。
Is there a way to have separate php error_logsfor each Virtual Host?
有没有办法error_logs为每个虚拟主机设置单独的 php ?
采纳答案by helloandre
To set the Apache(not the PHP) log, the easiest way to do this would be to do:
要设置Apache(而不是 PHP)日志,最简单的方法是:
<VirtualHost IP:Port>
# Stuff,
# More Stuff,
ErrorLog /path/where/you/want/the/error.log
</VirtualHost>
If there is no leading "/" it is assumed to be relative.
如果没有前导“/”,则假定它是相对的。
回答by Mat
The default behaviour is for error_log() to output to the Apache error log. If this isn't happening check your php.ini settings for the error_log directive - leave it unset to use the Apache log file for the current vhost.
默认行为是 error_log() 输出到 Apache 错误日志。如果没有发生这种情况,请检查您的 php.ini 设置中的 error_log 指令 - 保持未设置以将 Apache 日志文件用于当前虚拟主机。
回答by Kevin
I usually just specify this in an .htaccessfile orthe vhost.confon the domain I'm working on. Add this to one of these files:
我通常只在指定此.htaccess文件,或在vhost.conf对我工作的领域。将此添加到以下文件之一:
php_admin_value error_log "/var/www/vhosts/example.com/error_log"
回答by ejunker
My Apache had something like this in httpd.conf. Just change the ErrorLog and CustomLog settings
我的 Apache 在 httpd.conf 中有类似的东西。只需更改 ErrorLog 和 CustomLog 设置
<VirtualHost myvhost:80>
ServerAdmin [email protected]
DocumentRoot /opt/web
ServerName myvhost
ErrorLog logs/myvhost-error_log
CustomLog logs/myvhost-access_log common
</VirtualHost>
回答by hoyhoy
Have you tried adding the php_value error_log '/path/to/php_error_logto your VirtualHost configuration?
您是否尝试将 加入php_value error_log '/path/to/php_error_log到您的 VirtualHost 配置中?
回答by hoyhoy
You could try:
你可以试试:
<VirtualHost myvhost:80>
php_value error_log "/var/log/httpd/vhost_php_error_log"
</Virtual Host>
But i'm not sure if is going to work. I tried on my sites with no success.
但我不确定是否会起作用。我在我的网站上尝试过,但没有成功。
回答by James Hartig
Yes, you can try,
是的,你可以试试,
php_value error_log "/var/log/php_log"
in .htaccessor you can have users use ini_set()in the beginning of their scripts if they want to have logging.
in.htaccess或者你可以让用户ini_set()在他们的脚本的开头使用,如果他们想要记录的话。
Another option would be to enable scripts to default to the php.iniin the folder with the script, then go to the user/host's root folder, then to the server's root, or something similar. This would allow hosts to add their own php.inivalues and their own error_loglocations.
另一种选择是使脚本默认为php.ini包含脚本的文件夹,然后转到用户/主机的根文件夹,然后转到服务器的根目录,或类似的内容。这将允许主机添加他们自己的php.ini值和他们自己的error_log位置。
回答by James Hartig
php_value error_log "/var/log/httpd/vhost_php_error_log"
It works for me, but I have to change the permission of the log file.
它对我有用,但我必须更改日志文件的权限。
or Apache will write the log to the its error_log.
或者 Apache 会将日志写入其error_log.
回答by rkulla
Don't set error_logto where your syslogstuff goes, eg /var/log/apache2, because they errors will get intercepted by ErrorLog. Instead, create a subdirin your project folderfor logs and do php_valueerror_log "/path/to/project/logs". This goes for both .htaccessfiles and vhosts. Also make sure you put php_flaglog_errorson
不要设置error_log到你的syslog东西去的地方eg /var/log/apache2,因为他们的错误会被拦截ErrorLog。相反,subdir在您的项目文件夹中为日志创建一个并执行php_valueerror_log "/path/to/project/logs". 这适用于.htaccessfiles 和 vhosts。另外,还要确保你把php_flaglog_errors上
回答by Clutch
If somebody comes looking it should look like this:
如果有人来看,它应该是这样的:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/domains/example.com/html
ErrorLog /var/www/domains/example.com/apache.error.log
CustomLog /var/www/domains/example.com/apache.access.log common
php_flag log_errors on
php_flag display_errors on
php_value error_reporting 2147483647
php_value error_log /var/www/domains/example.com/php.error.log
</VirtualHost>
This is for development only since display_erroris turned on. You will notice that the Apache error log is separate from the PHP error log. The good stuff is in php.error.log.
这仅用于开发,因为display_error已打开。您会注意到 Apache 错误日志与 PHP 错误日志是分开的。好东西在php.error.log。
Take a look here for the error_reportingkey http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
看看这里的error_reporting关键http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting

