Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Apache configuration from PHP script

Tags:

php

apache

Particularly I need to know ErrorLog Apache configuration setting from PHP script to show the latest fatal errors.

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

like image 588
Gedrox Avatar asked Jul 20 '11 09:07

Gedrox


2 Answers

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.

like image 116
h0tw1r3 Avatar answered Oct 21 '22 01:10

h0tw1r3


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'));
?>
like image 22
marioosh Avatar answered Oct 21 '22 00:10

marioosh