NAME
Apache2::ASP::Manual::HttpdConf - Documentation about httpd.conf for Apache2::ASP
DESCRIPTION
To run Apache2::ASP under Apache, you need to set up the Apache configuration properly.
Apache configuration takes place in its httpd.conf
file.
Although you could simply place your configuration in the main httpd.conf
file, it is recommended that you instead use your local httpd.conf
file located under your application's root in conf/httpd.conf
.
To include your local httpd.conf
file in the global httpd.conf
, simply add the following line near the bottom of your global httpd.conf
:
# Config for Apache2::ASP application:
Include /path/to/your/app/conf/httpd.conf
The comment is important as well.
EXAMPLE
The following is an example httpd.conf
:
# !IMPORTANT!
# This is the libapreq2 config entry:
LoadModule apreq_module /usr/local/apache2/modules/mod_apreq2.so
# !IMPORTANT!
# This must be set before Apache2::ASP::PostConfigHandler is run:
PerlSetEnv APACHE2_ASP_APPLICATION_ROOT /var/www
# Load up some important modules:
PerlModule Apache2::ASP
PerlModule Apache2::ASP::PostConfigHandler
PerlPostConfigHandler Apache2::ASP::PostConfigHandler
# Configuration for MediaManager:
PerlModule Apache2::ASP::TransHandler
# Main website:
<VirtualHost *:80>
# !IMPORTANT!
# ServerName is not *required* for Apache2::ASP
# but is included here in the example, just as an example.
# *IF* you do include the ServerName directive, make sure it is correct!
ServerName whatever.com
# Where your *.asp scripts live:
DocumentRoot /var/www/html
# Set the directory index, so that /foldername/ will map to /foldername/index.asp:
DirectoryIndex index.asp
# Apache2::ASP::TransHandler converts /media/filename.txt urls so that they
# really mean /handlers/MediaManager?file=filename.txt
PerlTransHandler Apache2::ASP::TransHandler
# !IMPORTANT! Prevent anyone from viewing your GlobalASA.pm
<Files ~ (\.pm$)>
Order allow,deny
Deny from all
</Files>
# All *.asp files are handled by Apache2::ASP
<Files ~ (\.asp$)>
SetHandler perl-script
PerlHandler Apache2::ASP
</Files>
# All requests to /handlers/* will be handled by their respective handler:
<Location /handlers>
SetHandler perl-script
PerlHandler Apache2::ASP
</Location>
</VirtualHost>
WALKTHROUGH
Here, we'll walk through the configuration step-by-step so that you know what each directive is for.
# !IMPORTANT!
# This is the libapreq2 config entry:
LoadModule apreq_module /usr/local/apache2/modules/mod_apreq2.so
Apache2::ASP uses CGI::Apache2::Wrapper which requires Apache2::Request. Apache2::Request is part of the libapreq2
distribution.
Only add this directive if you have not already loaded up mod_apreq2.so
somewhere else in your global httpd.conf
file.
-------------------------------------------------------------------------------
# !IMPORTANT!
# This must be set before Apache2::ASP::PostConfigHandler is run:
PerlSetEnv APACHE2_ASP_APPLICATION_ROOT /var/www
This line sets $ENV{APACHE2_ASP_APPLICATION_ROOT}
to the value /var/www
Well, of course you already knew that.
This is important because Apache2::ASP::GlobalConfig has only limited abilities in guessing where you might have placed your web application. If this value is completely wrong, you might get an error in your server's error log that looks like this:
Cannot find configuration file anywhere! It should be found at $ENV{APACHE2_ASP_APPLICATION_ROOT}/conf/apache2-asp-config.xml
Don't panic - just make sure that you have set APACHE2_ASP_APPLICATION_ROOT
correctly to the top-level path of your application not your website's html directory.
While you're at it, make sure you take a look at the DIRECTORY STRUCTURE section of Apache2::ASP::Manual::Installation::Linux or Apache2::ASP::Manual::Installation::Windows.
-------------------------------------------------------------------------------
# Load up some important modules:
PerlModule Apache2::ASP
PerlModule Apache2::ASP::PostConfigHandler
First we simply load up Apache2::ASP
and Apache2::ASP::PostConfigHandler
.
Then, you see the line:
PerlPostConfigHandler Apache2::ASP::PostConfigHandler
PerlPostConfigHandler
may stand out as something very foreign to you. That's ok.
We're just telling the Apache webserver to execute Apache2::ASP::PostConfigHandler's handler()
method once its done reading the httpd.conf
files, but before it has spawned any child threads or processes.
Apache2::ASP::PostConfigHandler is in charge of loading up your conf/apache2-asp-config.xml
file once (and only once).
-------------------------------------------------------------------------------
# Configuration for MediaManager:
PerlModule Apache2::ASP::TransHandler
Apache2::ASP::TransHandler has the simple job of converting URLs that look like this:
/media/yourfile.jpg
Into URLs that look like this:
/handlers/MediaManager?file=yourfile.jpg
So here we load up it up via PerlModule
but we haven't yet done anything with it. That comes several lines later.
-------------------------------------------------------------------------------
# Main website:
<VirtualHost *:80>
We make a VirtualHost here. If you're not sure what that is, go ahead and Google it sometime.
The main idea is that all the other configuration directives we use within the VirtualHost
tags will not affect any other VirtualHost
configurations on your server.
-------------------------------------------------------------------------------
# !IMPORTANT!
# ServerName is not *required* for Apache2::ASP
# but is included here in the example, just as an example.
# *IF* you do include the ServerName directive, make sure it is correct!
ServerName whatever.com
This is pretty self-explanatory. Change whatever.com to whatever you are calling your website's hostname when you type its hostname into your browser. If you're not sure, just Google it.
-------------------------------------------------------------------------------
# Where your *.asp scripts live:
DocumentRoot /var/www/html
This should be pretty clear as well.
-------------------------------------------------------------------------------
# Set the directory index, so that /foldername/ will map to /foldername/index.asp:
DirectoryIndex index.asp
Use index.asp
because we're doing an Apache2::ASP website.
-------------------------------------------------------------------------------
# Apache2::ASP::TransHandler converts /media/filename.txt urls so that they
# really mean /handlers/MediaManager?file=filename.txt
PerlTransHandler Apache2::ASP::TransHandler
We've already loaded up Apache2::ASP::TransHandler but this line says "only do the url-translation for this website."
-------------------------------------------------------------------------------
# !IMPORTANT! Prevent anyone from viewing your GlobalASA.pm
<Files ~ (\.pm$)>
Order allow,deny
Deny from all
</Files>
If you don't do this, someone could read your GlobalASA.pm
as plaintext. Probably not a good thing.
-------------------------------------------------------------------------------
# All *.asp files are handled by Apache2::ASP
<Files ~ (\.asp$)>
SetHandler perl-script
PerlHandler Apache2::ASP
</Files>
Tells Apache that any requests that look like .asp
should be handled by Apache2::ASP.
-------------------------------------------------------------------------------
# All requests to /handlers/* will be handled by their respective handler:
<Location /handlers>
SetHandler perl-script
PerlHandler Apache2::ASP
</Location>
Tells Apache that any requests to yoursite.com/handlers/*
should be handled by Apache2::ASP.
Remember, Apache2::ASP will just prepare the ASP environment and then call your Handler module which would be located under your /handlers
directory.
For Linux installations see Apache2::ASP::Manual::Installation::Linux.
For Windows installations see Apache2::ASP::Manual::Installation::Windows.
-------------------------------------------------------------------------------
</VirtualHost>
Tells Apache that none of the configuration options we've set within the VirtualHost
tags above should affect any of the other VirtualHost
setups you have on the same server.
BUGS
It's possible that some bugs have found their way into this release.
Use RT http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP to submit bug reports.
HOMEPAGE
Please visit the Apache2::ASP homepage at http://apache2-asp.no-ip.org/ to see examples of Apache2::ASP in action.
AUTHOR
John Drago mailto:jdrago_999@yahoo.com
COPYRIGHT AND LICENSE
Copyright 2007 John Drago, All rights reserved.
This software is free software. It may be used and distributed under the same terms as Perl itself.