Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

How to configure Apache for running perl scripts.

by munu (Novice)
on Aug 06, 2004 at 13:51 UTC ( [id://380536]=perlquestion: print w/replies, xml ) Need Help??

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

I have this simple program a.pl in var/www/html1 directory.
#!/usr/bin/perl
print "hello world";

in /etc/httpd/conf/httpd.conf file i made the following changes
1. DocumentRoot "/var/www/html1"
2. <Directory "var/www/html1">
3. ScriptAlias /cgi-bin/ "/var/www/html1"
4. <Direcory "/var/www/html1">
5. AddHandler cgi-script .cgi .pl

when i type http://myIPaddress/a.pl in any browser It is displying the contents of the perl file.
I want to know how to execute this script from the browser.

Thanks
MUNU
  • Comment on How to configure Apache for running perl scripts.

Replies are listed 'Best First'.
Re: How to configure Apache for running perl scripts.
by dsb (Chaplain) on Aug 06, 2004 at 13:57 UTC
    You have to configure Apache to handle Perl scripts. This might be a good place to start before you go showing off your source code :).

    You also need to print out valid HTTP headers before you can print any web content. Something your tiny script does not do.

    print "Content-type: text/html\n\n";
    or even better:
    use strict; use CGI; my $q = CGI->new(); print $q->header("text/html");


    dsb
    This @ISA my cool %SIG
      Now I have added the lines you have specified..
      But now it is telling that "you do not have permission to access a.pl on this server".
      BUT I DID "chmod 777 a.pl".
      In /httpd/logs/errlog file it is mentioned that "optionsExecCGI is off in this directory /var/www/html1/a.pl"
      suEXEC mechanism is enabled

        It is probably the permissions on the directory. You do not want the program to be rwx by the world, 755 should be sufficient - also with suExec it will protest at running things that appear to be owned by someone other than the user the script will be run at.

        /J\

Re: How to configure Apache for running perl scripts.
by sunadmn (Curate) on Aug 06, 2004 at 13:59 UTC
    Well I am sure there can be many different levels of issues here, but first I would suggest checking that the script is executable this file should be chmod 755. Also you might need to ensure your Apache build was configured with suexec enabled.

    SUNADMN
    USE PERL
      Yes I had done chmod 777 a.pl, but it is still displaying the contents of the file.
      And how to check if Apache is build with SUexec or not
Re: How to configure Apache for running perl scripts.
by Gilimanjaro (Hermit) on Aug 06, 2004 at 14:16 UTC
    Your combining two different ways of enable scripts:
    <Directory "/var/www/html1"> ScriptAlias /cgi-bin/ "/var/www/html1" </Directory>
    Enables your scripts under http://myIPaddress/cgi-bin/a.pl

    AddHandler cgi-script .cgi .pl
    Would enable your script to run everywhere in your DocumentRoot, but you'll also need:
    <Directory "/var/www/html1"> Options +ExecCGI </Directory>
    ScriptAlias sets up an alias, and does the +ExecCGI implicitly for the location.

    If you don't want to be bound by your location, you need to explicitly add ExecCGI rights, and tell Apache to recognize the .pl extension.

    Please consider using mod_perl though, if you want to be nice to your server...

      I have added "Options +ExecCGI" line as you told.
      But there are 2 similar places where i can add. And I have added the line in 2 places.

      But in error log it is still saying that "ExecCGI is not enabled".
        The error message means:
        • Apache has found the script at the url you specified
        • Apache recognizes the extension, and is trying to use the cgi-script handler
        • But Apache's failsafe mechanism which required that ExecCGI is explicitly enabled is blocking you

        Look for other 'Options' directives, maybe below your +ExecCGI one, that disable it again (maybe not explicitly, but possibly by specifying None).

        Please take a good look at Apache's documentation on the Option directive and Directory, Location and Files blocks. Also make sure there are no .htaccess files around which override your Options directives. Without your complete apache config it's hard to exactly determine the exact cause. If you can't find it with these tips, put it on the web somewhere, and send me a message with the url. I'll have a look at it for ya...

Re: How to configure Apache for running perl scripts.
by trantor (Chaplain) on Aug 06, 2004 at 14:18 UTC

    Did you add something like Options +ExecCGI between <Directory> and </Directory>?.

    What does the error log say? In my experience, you can solve 95% of your configuration problems by looking at it.

      the error log says ExecCGI is off.
      There are lots of <Directory> tabs present.
      So can you please specify in which directory tab I should put the "Options +ExecCGI"

        Er, in all the directories where you want CGIs to be executed of course.

        Looking at your configuration snippets, the <Direcory "/var/www/html1"> section seems like a good candidate.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://380536]
Approved by sunadmn
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2024-04-19 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found