Is it possible for PHP to read/parse the current vhosts’ Apache VirtualHost config block, in particular, to retrieve ErrorLog and CustomLog settings?
To be clear we do not need the PHP error log path, that is easy to retrieve.
I couldn’t find any way in phpinfo or _SERVER/getenv() or PHP Apache functions (apache_module(), apache_note(), apache_getenv())
The codebase is used for multiple virtual hosts on multiple servers so we can’t hard code the Apache access and error log paths in PHP (or in .htaccess SetEnv or some ini/csv/whatever file etc), as it may not always match up with what has been set in <VirtualHost> – someone in Operations may update the VirtualHost but a developer may not update the code or whatever the code is using to find the same path. We cannot have a SetEnv under or above the line of CustomLog with the same value, as it’s still possible one will be updated without the other (human error etc.).
My best hope was apache_getenv() but I’ve tried apache_getenv('CustomLog') and it does not return anything.
Would be ok to run a series of system()/exec() calls to run cli functions to find them, but not ideal.
The ServerName may not match the current vhost being called, as ServerAlias may have a different virtualhost that contains regex, so once the path to Apache conf has been found, manually grepping through the file is not ideal/reliable.
Apache 2.2.16 (Unix)
PHP 5.3.3
CentOS release 5.5 (Final)
Please tell me I’ve missed something obvious 😉
No, you haven’t. Apache simply does not store this string anyplace where you can get at it. From, mod_log_config.c (note the
fmtargument which is stored in aconfig_log_statestruct):You must either (regardless if you’ve previously stated that you cannot):
Modifymod_log_config.c(bad idea!)