rjahrman has asked for the wisdom of the Perl Monks concerning the following question:

To use ModPerl, do I have to put the extra lines in my http.conf file? Will htaccess do? Also, I thought I heard that there was a way to simply "include" a library at the top of a Perl script to use ModPerl. Is this true?

Replies are listed 'Best First'.
Re: Using ModPerl
by perrin (Chancellor) on Jan 30, 2004 at 04:38 UTC
    I think the other answers here were a little quick on the trigger. You can't do everything in an htaccess file, but you can do a lot. The details (for mod_perl 1.x) are covered here.

    As for your second question, you don't even have to do that much to use mod_perl. If you set up Apache::Registry or Apache::PerlRun, you can run existing CGI scripts without changes. You will run into problems though if they are sloppy scripts that don't pay attention to issues like variable scoping. This is all covered in The Guide.

Re: Using ModPerl
by jdtoronto (Prior) on Jan 30, 2004 at 03:51 UTC
    To use ModPerl, do I have to put the extra lines in my http.conf file?

    You need to add an alias directive so that you have a directory which is where you will place your mod_perl scripts. Then you need to add a Location directivev which configures the directory so that files therein are handled by the Apache::Registry Handler and executed under mod_perl.

    Will htaccess do?

    No

    Also, I thought I heard that there was a way to simply "include" a library at the top of a Perl script to use ModPerl. Is this true?

    No, the grunt work of mod_perl itself is done at Apache startup time.

    Running in Apache::Registry mode it is often possible to run existing CGI scripts under mod_perl to get the performance benefits without significant re-writing. Of course, the scripts need to be "well behaved" in their use of global variables. The book Practical mod_perl will provide invaluable advice and information, as will the basic mod_perl documentation from the apache.org website. Their are specific sections of the doc's on just these issues.

    jdtoronto

Re: Using ModPerl
by Zaxo (Archbishop) on Jan 30, 2004 at 03:27 UTC

    It needs to be set up in httpd.conf and httpd should be told to reload configuration with SIGHUP or its control script.

    The second is untrue.

    After Compline,
    Zaxo

Re: Using ModPerl
by CountZero (Bishop) on Jan 30, 2004 at 06:41 UTC
    As you know, .htaccess files are read every time you access a directory in which they are "activated".

    Putting your mod-perl related directives into a .htaccess file would really defeat the whole purpose of mod-perl which is to provide you with a persistent perl interpreter which keeps in memory the "compiled" version of your script, thus improving its performance.

    If you will re-initiate the mod-perl environment every time you access one of the scripts it will run, you are likely to be much slower than by using ordinary CGI.

    Just to be curious: why would you put the mod-perl directives in a .htaccess file?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law