Get Apache configuration with PHP script

In particular, I need to know ErrorLog configuring Apache from a PHP script to show the latest fatal errors.

Can PHP get such a parameter or do I need to go through the log path manually?

+6
source share
4 answers

As far as I know, Apache will not disclose this information to PHP, even if it works as an Apache module. You have two options:

  • If you are running a 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 manage the server, you can simply check the *.conf files yourself.

  • You can always configure PHP to send your errors to a known place (I would say that this is the most common approach). You can use the error_log and log_errors directives of PHP.

+2
source

PHP does not have a built-in command to search the apache error log. Alternatively, you can do something similar in the apache configuration.

 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.

+3
source

To get the Apache configuration, you can configure the mod_info module. Take a look at this one . You get the Apache configuration at the link: http: // localhost / server-info . Here is a living example.

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

To get this information in php you can use:

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

This will give you every part of php configuration

I'm not sure if you can get the apache configuration though

0
source

Source: https://habr.com/ru/post/893145/


All Articles