Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a variable in apache's httpd.conf file?

Tags:

apache

I want to define a variable in Apache server's httpd.conf configuration file.

Ex: variable static_path = C:\codebase\snp_static

and I want to use this variable (static_path) in httpd.conf where ever required.

Please tell me how can define a variable in httpd.conf file ?

like image 781
Satya Avatar asked Jul 04 '11 08:07

Satya


People also ask

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.

How configure Apache conf file?

All the configuration files for Apache are located in /etc/httpd/conf and /etc/httpd/conf. d . The data for websites you'll run with Apache is located in /var/www by default, but you can change that if you want.

Where are Apache environment variables?

Apache's Environment variables are stored in /etc/apache2/envvars in Ubuntu, /etc/sysconfig/httpd in Redhat and at /etc/rc.


2 Answers

Within httpd.conf, declare your variable(s) with: Define (Preferably at the very first line)
Syntax: Define variable-name variable-value

In this manner:

#The line below creates the variable [static_path] Define static_path C:/codebase/snp_static 

You can later use this variable like so:

ServerRoot = ${static_path} ... DocumentRoot = ${static_path} ... <Directory ${static_path}> ...etc. 

You can even combine multiple variables:

#Below, I am going to combine variables [server_space] and [static_path] Define server_space c:/ Define static_path codebase/snp_static ... ServerRoot = ${server_space}${static_path} ... DocumentRoot = ${server_space}${static_path} ... <Directory ${server_space}${static_path}> ...etc. 

Documentation: http://httpd.apache.org/docs/2.4/mod/core.html#define

like image 155
Omar Avatar answered Sep 22 '22 06:09

Omar


If all you want is simple variable substitution inside httpd.conf, then define an ordinary shell environment variable for the user that runs Apache, then use the ${ENVVAR} syntax to refer to it inside your httpd.conf file, see Apache docs

like image 34
maxpolk Avatar answered Sep 25 '22 06:09

maxpolk