httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: [users@httpd] Using environment variable in httpd.conf
Date Thu, 19 Jan 2006 20:09:30 GMT

Well, I have just found something interesting while reading 
through Pro Apache 3rd edition, by Peter Wainwright.
Apparently, using mod_perl, you can use the full power of 
the pearl interpreter INSIDE httpd.conf.

Quote from the book page 449:

"Embedded Perl appears in Apache's configuration inside a 
<Perl>...</Perl> container, also known as a Perl section.
Anything inside this container is executed by mod_perl when 
Apache starts. You specify configuration directives simply 
by assigning a package variable of the same name. For 


In Perl, this is a basic assignment of a string to a scalar 
variable. In a Perl section, it becomes a configuration 
directive because the variable corresponds to the name of a 
configuration directive understood by Apache."

Peter Wainwright also provides some very capable examples 
in his book, using this technique.

One example of this starts with:

#Now write the Perl script and embed it into httpd.conf in 
# a <Perl> container


# generate virtual hosts on the fly with Perl
# back to httpd.conf

# of httpd.conf...


# note the following line calls an external perl interpreter
#!/usr/bin/perl -w

# rest of Perl script - embedded in htpd.conf

# back to httpd.conf

#rest of httpd.conf file

He concludes this section of the chapter by stating,

"Of course you could use any scripting language to create a 
configuration file this way because Apache no longer needs 
to know how to interpret it (ie the script) itself."

So, in theory (please see disclaimer below - LOL) it should 
be possible to use an external php interpreter to generate 
httpd.conf files and configuration directives this way, by 
embedding the call to the php interpreter into a 
<Perl>...</Perl> section.

The above was extracted from the full sample chapter 7, 
'Hosting more than one website', available for download from 
Apress's website, at:

The download link is not underlined, and is the text 
'Download Sample Chapter' which just looks like a 
sub-heading to me.

Pro Apache, Third Edition
Download Sample Chapter <-- 

This is an excellent book, packed with practical 
explanations of how to master Apache. I have struggled with 
the online documentation for years. I cannot recommend this 
book highly enough!



In theory, theory and practice are the same;
In practice they are not. 

On Thu, 19 Jan 2006 wrote:

> To:
> From:
> Subject: Re: [users@httpd] Using environment variable in httpd.conf
> Thanks for the info Joshua.
> I was just curious to know if it was possible to set 
> variables in httpd.conf . Probably won't need to 
> use such a feature at the moment.
> Keith
> In theory, theory and practice are the same;
> In practice they are not. 
> On Thu, 19 Jan 2006, Joshua Slive wrote:
> > To:
> > From: Joshua Slive <>
> > Subject: Re: [users@httpd] Using environment variable in httpd.conf
> > 
> > On 1/19/06, <> wrote:
> > >
> > > Well Tom, I'm using apache 2.0.50 under SuSE 9.2 pro and
> > > just added the following to httpd.conf, after my LoadModule statements:
> > >
> > > SetEnv ErrLogPath /var/log/apache2/error_log
> > > ErrorLog ${ErrLogPath}
> > > LogLevel debug
> > >
> > > All this does for my setup is create an error_log file under
> > > /srv/www/ called ${ErrLogPath}.
> > >
> > > Am I missing something?
> > 
> > The undocumented env-variable-in-config-file feature looks at
> > variables in the server environment at time of startup.  SetEnv
> > doesn't actually make real environment variables until a cgi script is
> > launched.  See:
> >
> > 
> > What you want sounds more like the features provided by mod_macro. 
> > See
> > 
> > But the standard advice in cases like this is: httpd.conf is not a
> > programming language, it is a config file.  If you need more advanced
> > features, then use your favorite preprocess (m4, etc) to generate your
> > config files.
> > 
> > Joshua.

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message