Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6115533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:06:08+00:00 2026-05-23T15:06:08+00:00

Is it possible for PHP to read/parse the current vhosts’ Apache VirtualHost config block,

  • 0

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 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:06:08+00:00Added an answer on May 23, 2026 at 3:06 pm

    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 fmt argument which is stored in a config_log_state struct):

    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 either (regardless if you’ve previously stated that you cannot):

    • Convince the developers to keep SetEnv and CustomLog identical
    • Parse the conf files yourself and keep your fingers crossed
    • Modify mod_log_config.c (bad idea!)
    • Forget the whole thing! 😉
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible for someone to 'hack' an apache server and read PHP files.
Is it possible to read the data in the php $_SESSION array in the
Using PHP, it's possible to read off the contents of a file using fopen
Is it possible to read and write Word (2003 and 2007) files in PHP
Is it possible to read cookie expiration time with php ? When I print_r($_COOKIE)
Possible Duplicate: PHP: Check who had read sent email? I'm writing a tool in
I read it's possible to use C/C++ code in PHP by writing an extension.
Is it possible to read a database through php without knowing the fields names?
Possible Duplicate: Can PHP read the hash portion of the URL? Hi, I want
Is there any way to make Apache to read PHP documents from RAM? I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.