Apache and Perl

How can I configure Apache Web Server(running on Windows Platform) so that I can use CGI scripts written in Perl ?

I would be grateful for all help offered regarding this.

Thanks in advance

John Clarke
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'm assuming you already have ActivePerl installed on your Windows machine (http://www.activestate.com).

After that, do this, which I lifted directly from the ActivePerl documentation:

How do I use Perl for Win32 under Apache?

NOTE: mod_perl currently only works when Perl is built without PERL_OBJECT support on win32. Since ActivePerl is built under the PERL_OBJECT regime, mod_perl users will need to build Perl from the sources.

If you want to put all of your CGI scripts into one directory, add the following line to your srm.conf file (You can choose any directory you'd like, but make sure it exists):

    ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache/cgi-bin/"

After you have made this change, stop and restart the Apache service.

Apache provides an emulation of the UNIX shebang (#!/path/to/perl) syntax, so the next step is easy. You can put you Perl scripts into your cgi-bin directory, as long as you have a path to a valid interpreter at the top. For example:

    use CGI qw(:standard) ;
    print header();
    print "Hello, world";

If you want to enable CGI scripts based on an extension, such as .pl, you need to add the following line to srm.conf:

    AddHandler cgi-script .pl

By default, CGI scripts are not allowed in your DocumentRoot directory, but they are allowed in other document directories. Document directories are created with the Alias command in srm.conf:

    Alias /ResourceKit/ "E:/utilsamp/"

You can then include files that end in .pl within a document directory. You will still need to include the #! line with the full path to the perl.exe interpreter, as shown earlier.

If you want to allow CGI scripts in the DocumentRoot directory, add the ExecCGI option to the Options directive between the <Directory> and </Directory> entry for your DocumentRoot in access.conf (these appear directly after the comment titled:

    # This should be changed to whatever you set DocumentRoot to.
After you have updated it, your Options directive may look something like:

    Options Indexes FollowSymLinks ExecCGI


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.