Search code examples
phpapacheconfigurationwebserver

Expression not evaluated in httpd.conf


I am trying to come up with a way to switch between projects and production/development through environment variables. However it when I do this:

Define PROJECT_ROOT osenv('APACHE_PROJECT_ROOT') LogMessage ${PROJECT_ROOT}

The right side of the Define expression is treated as a sting and not evaluated. The result is "osenv('APACHE_PROJECT_ROOT')" instead of the environment variable itself. Any suggestions?

edit: Some further clarification as this post is not getting the views or answers I expected. I want to have a development, staging and production environment.

On my development machine, I expect to have multiple apache projects running, each with a virtualhost settings file. The correct path to the directory and the virtualhost settings could be derived from (OS) environment variables APACHE_PROJECT_ROOT and APACHE_ACTIVE_PROJECT.

The staging and production environment would work similar (perhaps simplified, since there is only one project per droplet. It seems to me like common sense to have one http.conf file, where the OS environment variables determine what sites are loaded. I am not really finding any resources on this though.


Solution

  • Define is not documented as taking an expression as an argument, so it should be no surprise that the value ends up as the literal value you specify.

    You can use native environment variables directly as values with ${VAR} syntax in most contexts because it is handled why the configuration is read. That resolves any alternate paths to DocumentRoot or log directories, but doesn't give you conditionals.

    The most reasonable way to do conditionals at config file parsing time is to pass -D to specify which environment you're in and then to vary the directives used.