开发者

Get Apache configuration from PHP script

Particularly I need to know ErrorLog Apache configuration setting from PHP script to show the latest fatal e开发者_Go百科rrors.

Can PHP obtain such setting or I need to pass the log path manually?


PHP does not have a built-in command for locating the apache error log. As an alternative, you could do something like this in the apache config.

ErrorLog /var/log/apache/error_log
SetEnv APACHE_ERROR_LOG /var/log/apache/error_log
PassEnv APACHE_ERROR_LOG

In your PHP script $_SERVER['APACHE_ERROR_LOG'] should be what you are asking for.


To get Apache configuration You can setup mod_info module. Look at this. You get Apache configuration at link: http://localhost/server-info. Here live example.

<Location /server-info>
    SetHandler server-info
    AllowOverride All
    Order allow,deny
    Allow from all
</Location>

To get this info in php You could use:

<?php
    echo(file_get_contents('http://localhost/server-info'));
?>


As far as I know, Apache will not reveal that information to PHP, even if it runs as Apache module. You have two possibilities:

  • 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();
?>

This will give you every part of php configuration

I'm not sure you can get apache configuration though

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜