Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use variables in httpd.conf

Is there a way to use variables of some sort in an apache httpd.conf file? I'd like to define a value and use it throughout a block, as in

define myvar somename #or whatever the syntax would be alias /my/path "/some/path/${myvar} #or whatever the syntax would be 
like image 239
Paul Spencer Avatar asked Jan 13 '11 20:01

Paul Spencer


People also ask

How do I set environment variables in httpd conf?

You can get environment variables substituted in to the config file at start up with the ${ENVVAR} syntax. It's up to you to figure out how to set those variables before starting up the server. Note that these variables will persist so any scripts in languages like php will be able to read them.

How do I declare a variable in Apache?

The most basic way to set an environment variable in Apache is using the unconditional SetEnv directive. Variables may also be passed from the environment of the shell which started the server using the PassEnv directive.

Can I edit httpd conf?

You can't edit httpd. conf. You'll need to make any changes necessary in an . htaccess file - you can override most stuff you'd need to override in here.

Is httpd conf and apache2 conf same?

Apache is configured by placing configuration directives, such as Listen and ServerName , into a configuration file, which will be read by the Apache executable during the startup. The default configuration file is called " httpd. conf " (or " apache2.


1 Answers

Yes, kind of. You can get environment variables substituted in to the config file at start up with the ${ENVVAR} syntax. It's up to you to figure out how to set those variables before starting up the server.

http://httpd.apache.org/docs/2.2/configuring.html#syntax

Note that these variables will persist so any scripts in languages like php will be able to read them.

Also it's important to note that these values are interpreted once only when the server starts up so they're more like constants than variables.

Update

As of httpd version 2.4, see this answer instead: https://stackoverflow.com/a/15731921/498798

like image 150
noodl Avatar answered Sep 21 '22 05:09

noodl