我特别需要知道如何从PHP脚本中获取ErrorLog
Apache配置设置,以显示最新的致命错误。
PHP能否获取此设置,还是我需要手动传递日志路径?
要获取Apache配置,您可以设置mod_info
模块。请参考此链接。
您可以在链接http://localhost/server-info中获取Apache配置。这里有一个实例。
<Location /server-info>
SetHandler server-info
AllowOverride All
Order allow,deny
Allow from all
</Location>
要在PHP中获取此信息,您可以使用以下代码:
<?php
echo(file_get_contents('http://localhost/server-info'));
?>
PHP没有内置命令来定位Apache错误日志。作为替代方案,您可以在Apache配置中执行以下操作。
ErrorLog /var/log/apache/error_log
SetEnv APACHE_ERROR_LOG /var/log/apache/error_log
PassEnv APACHE_ERROR_LOG
If you control the server, you can enable the mod_info Apache module. It generates an HTML page that looks like this:
In file: C:/Archivos de programa/Apache Software Foundation/Apache2.2/conf/sitios.d/foo.conf
4: <VirtualHost *:80>
5: ServerName foo
7: DocumentRoot "C:/Sites/Foo/htdocs"
9: ErrorLog logs/foo-error.log
12: <Directory "C:/Sites/Foo/htdocs">
13: AllowOverride All
14: Options Indexes FollowSymLinks
: </Directory>
: </VirtualHost>
Of course, if you control the server you can simply inspect the *.conf
files yourself.
You can always configure PHP to send its errors to a known location (I'd say this is the most common approach). You can use the error_log and log_errors PHP directives.
<?php
phpinfo();
?>
这将提供您 PHP 配置的每个部分
但我不确定您是否可以获取 Apache 配置