Is it possible for PHP to read / parse the current Apache VirtualHost vhosts configuration block to get the ErrorLog and CustomLog settings?

Is it possible for PHP to read / analyze the current Apache VirtualHost vhosts configuration block, in particular, to get the ErrorLog and CustomLog settings?

To be clear, we do not need a path to the PHP error log that is easy to obtain.

I could not find any way in phpinfo or _SERVER/getenv() or PHP Apache ( apache_module() , apache_note() , apache_getenv() )

The code base is used for several virtual hosts on several servers, so we can’t hard-code the access paths for Apache access files and errors in PHP (or in .htaccess SetEnv or some ini / csv / any file, etc.), since it does not always match what was set in <VirtualHost> - one of the Operations can update VirtualHost, but the developer cannot update the code or something that uses the code to find the same path. We cannot have a SetEnv below or above the CustomLog line with the same value, since it is still possible that it will be updated without another (human error, etc.).

My best hope was apache_getenv() , but I tried apache_getenv('CustomLog') and it returns nothing.

It would be nice to run a series of calls to system()/exec() to run cli functions to find them, but not perfect.

ServerName may not match the current vhost being called, because ServerAlias may have a different virtual host that contains the regular expression, therefore, as soon as the path to Apache conf is found, manually grepping through the file is not ideal / reliable.

Apache 2.2.16 (Unix) PHP 5.3.3 CentOS Version 5.5 (Final)

Please tell me, I missed something obvious;)

+4
source share
2 answers

Say that I missed something obviously;)

No no. Apache just does not save this line anywhere you can get it. From, mod_log_config.c (note the fmt argument, which is stored in the config_log_state structure):

 static const char *add_custom_log(cmd_parms *cmd, void *dummy, const char *fn, const char *fmt, const char *envclause) { const char *err_string = NULL; multi_log_state *mls = ap_get_module_config(cmd->server->module_config, &log_config_module); config_log_state *cls; cls = (config_log_state *) apr_array_push(mls->config_logs); cls->condition_var = NULL; if (envclause != NULL) { if (strncasecmp(envclause, "env=", 4) != 0) { return "error in condition clause"; } if ((envclause[4] == '\0') || ((envclause[4] == '!') && (envclause[5] == '\0'))) { return "missing environment variable name"; } cls->condition_var = apr_pstrdup(cmd->pool, &envclause[4]); } cls->fname = fn; cls->format_string = fmt; if (fmt == NULL) { cls->format = NULL; } else { cls->format = parse_log_string(cmd->pool, fmt, &err_string); } cls->log_writer = NULL; return err_string; } 

You must (regardless of what you said earlier that you cannot):

  • Persuade developers to keep the same SetEnv and CustomLog values
  • Collect the conf files yourself and cross your fingers.
  • Modify mod_log_config.c (bad idea!)
  • Forget everything!;)
0
source

This is a kind of hacking, but you can bet

 ErrorLog /path/to/logfile SetEnv ErrorLog /path/to/logfile 

in your httpd.conf so you can use the apache_getenv () function. getenv () does not retrieve configuration directives, but only the actual environment variables. So put the log path in the environment variable.

+1
source

All Articles