Keletso Mokgethi wrote:
> i am a novice trying to run a perl script on apache

> i created
> a directory under httpd called "perl" in which i
> stored the script. according to redhat's linux 6.2
> apache/ssl documentation, mod_perl is ready to run
> once the server is launced and there is no need for
> any changes in httpd.conf

Hold it right there! If you created a directory, you had better tell
apache about it - for that you *need* to edit httpd.conf... let's
proceed.

> hoping to run the script i entered the URL:
> http://localhost/perl/Read_dat.perl/
> 
> and got the reponse: Forbidden
> 
> "you don't have permission to access
> /perl/Read_dat.perl/ on this server.

There are a few reasons why you might get this... In short, apache has
to be able to find the program and access to the directory has to be
"allowed". 

Before doing anything else, look in httpd.conf until you find the
ErrorLog directive, then find the file it is pointing to and tail that
file while you run your prog to see what errors you are getting ($ tail
-f /home/apache/logs/error_log)

Back to the problem: I think you are trying to run your script using the
Apache::Registry. To do this:

- let's assume your ServerRoot is "/home/apache"
- check mod-perl is compiled into apache ($ /home/apache/bin/httpd -l
and look for mod_perl)
- put your script in /home/apache/perl (already done)
- check it is executable ($ chmod +x Read_dat.perl)
- its first output has to be the script-header (print "Content-type:
text/html\n\n"; - NB note the two "\n").
- in httpd.conf, you need the following

<Directory /home/apache/perl>  # this "allows" apache into the directory
  Allow from all
</Directory>

Alias /perl/  /home/apache/perl/ # this lets it find the script
<Location /perl>                 # this tells it what to do
  SetHandler  perl-script
  PerlHandler Apache::Registry
  Options +ExecCGI
</Location>
- restart apache
- hit the URL; http://localhost/perl/Read_dat.perl

By the way, in case you don't actually have mod_perl, bear in mind that
you don't need to use mod_perl to get apache to execute a perl program.
You can just use plain old-fashioned CGI. A simple configuration that
might get you running quicker is:

- create a directory /home/apache/cgi and put Read_dat.perl into it
- make sure it is executable 
- its first output has to be the script-header (print "Content-type:
text/html\n\n"; - NB note the two "\n").
- in httpd.conf:

<Directory /home/apache/cgi>
  Allow from all
</Directory>
DocumentRoot /home/apache/html
ScriptAlias /cgi /home/apache/cgi

- restart apache
- hit the URL; http://localhost/cgi/Read_dat.perl

Now you should get some output. 

Check the error_log to see if anything goes wrong (this will log
apache-level errors). If you need to debug your program, switch on
script-logging:

ScriptLog logs/script_log

and this will log STDERR from the script.

best regards,

Owen Boyle.

Reply via email to