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

I cannot get Perl to execute correctly. I have an html doc that references it. When I click the submit button instead of running the perl script it opens the code in the browser. I'm running on Windows with an Apache webserver. I have compiled the code so I know the syntax is okay and perl is working. I uploaded a simple test file to double check perl and paths and everything worked fine there.
  • Comment on How do I get my webserver to execute Perl CGI scripts?

Replies are listed 'Best First'.
Re: How do I get my webserver to execute Perl CGI scripts?
by Velaki (Chaplain) on Sep 02, 2004 at 16:24 UTC

    Some perl programs need to have certain extensions, such as .pl or .cgi, in order to be run by the web server. Others need to be placed in particular directories, such as cgi-bin. It depends on how your web server is configured.

    Speak to your web/system administrators, and ask them how you must configure your perl program, how it should be named, and where it must be placed in order to run.

    Hope that helped,
    -v
    "Perl. There is no substitute."
Re: How do I get my webserver to execute Perl CGI scripts?
by wfsp (Abbot) on Sep 02, 2004 at 16:25 UTC
Re: How do I get my webserver to execute Perl CGI scripts?
by kutsu (Priest) on Sep 02, 2004 at 16:39 UTC
      I did everything that was suggested here and in referenced entries. I compiled the code and it's syntax was fine. I uploaded a test.cgi to check if perl was running and it worked without problem. I'm running on Windows with an Apache server if that makes a difference.
        Been there, got the teeshirt. It's like trying to stir your tea with a barge pole.
        If it's any help, this is what I did the last time I was there.

        At the begining of the script, send a message to the browser and exit.

        If that's ok, move the message down a bit and try again!

        Or

        Add a bit more code to the test.cgi.

        It that's ok, add a bit more!

        Have a look at the docs again and use CGI::Carp in test.cgi. Send plenty of output to the browser.

        Then (and only then!) post a short script that doesn't work here.

        This has saved my sanity many times! Best of luck.

Re: How do I get my webserver to execute Perl CGI scripts?
by jbodoni (Monk) on Sep 02, 2004 at 18:53 UTC
    The ActivePerl User Guide contains the following information:

    How do I use ActivePerl under Apache?

    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:

    #!C:\PERL\5.00464\bin\MSWin32-x86\perl.exe 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

Re: How do I get my webserver to execute Perl CGI scripts?
by amonroy (Scribe) on Sep 02, 2004 at 17:31 UTC
    Make sure to have something like this in your httpd.conf: ScriptAlias /some/path /location/of/cgi/script.cgi