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 ?
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.
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.
Apache's Environment variables are stored in /etc/apache2/envvars in Ubuntu, /etc/sysconfig/httpd in Redhat and at /etc/rc.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With