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

SOLVED! Apache mod_perl + mod_cgi in same directory

Thanks Keith for your suggestions.  In the end, I settled upon a variation of
what you suggested.

My goal:  to allow my users to create static and dynamic HTML pages in their
own home directories using both CGI and PERL as they liked.  Basically, I 
wanted to be able to serve CGI and PERL-CGI out of the same directory.

The Problem:  mod_cgi and mod_perl both provide CGI services.  If you attempt
to set them up under the same directory, only one of them will work.

The Solution:

NOTE:  I use only one config file:  httpd.conf in accordance with current 
       Apache configuration practices.

1.  I enabled mod_userdir during installation of my Apache 1.3.17 server and 
    set the UserDir to "public_html".  This means that anywhere under the 
    user's home directory, they can create a "public_html" directory from 
    which to serve web pages:

    <IfModule mod_userdir.c>
	UserDir public_html

2.  I disabled the UserDir for Root, per suggestion from Apache's website:
    UserDir disabled root

3.  I set the controls on the public_html directory as follows:

    <Directory "/home/*/public_html">
	Options +ExecCGI +Includes +Indexes
	AllowOverride None
	Order Allow,Deny
	Allow from All

4.  CGIs are enabled in the public_html directory (+ExecCGI) and can be 
    served from outside /usr/local/apache/cgi-bin because the following lines 
    were enabled in the mod_mime section of the configuration file:

    AddHandler cgi-script .cgi

    Now, any file ending in ".cgi" will be handled by the "cgi-script" handler

5.  I wanted something equivalent to step four for handling perl-script files.
    The solution was to create a LocationMatch so that any URL ending in  a 
    predefined regular expression would be handed off to the PerlHandler. The
    form of the expression to be matched was "/somefile.pl"

    <LocationMatch "\/*\.pl$">
    	SetHandler perl-script
        PerlHandler Apache::Registry
	PerlSendHeader On

Caveats:  This is not the most secure solution in the world.  If you do not
personally know your users, as I do, and/or you do not trust them, I suggest 
you stick with the Apache recommended approach of creating a cgi-bin and/or
perl-bin directories and only allow cgi's served out of those directories.
Since my webserver is for development purposes, I wanted greater flexibility.

Now both .cgi and .pl files can reside in the same directory and each is 
handled by the appropriate Handler.

robert a. jacobs

Reply to: