Re: [users@httpd] Using environment variable in httpd.conf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 
example;

<Perl>
 $ServerAdmin="webmaster@xxxxxxxxxxxxxxxxx";
</Perl>

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

<Perl>

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

# ...rest of httpd.conf...

and,

<Perl>
# 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
<Perl>

#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:

http://www.apress.com/book/supplementDownload.html?bID=275&sID=2134

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!

HTH

Keith

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

On Thu, 19 Jan 2006 httpd2@xxxxxxxxxxxx wrote:

> To: users@xxxxxxxxxxxxxxxx
> From: httpd2@xxxxxxxxxxxx
> 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: users@xxxxxxxxxxxxxxxx
> > From: Joshua Slive <joshua@xxxxxxxx>
> > Subject: Re: [users@httpd] Using environment variable in httpd.conf
> > 
> > On 1/19/06, httpd2@xxxxxxxxxxxx <httpd2@xxxxxxxxxxxx> 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:
> > http://httpd.apache.org/docs/2.2/env.html
> > 
> > What you want sounds more like the features provided by mod_macro. 
> > See http://modules.apache.org/.
> > 
> > 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:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux