-1

I Successfully installed Apache web server in my local machine. My question is how to run perl cgi script on this server Actully I don't have any Idea that's why posted question here. my sample cgi script is

#!/perl/bin/perl -w
use strict;
use warnings;
print "Content-type: text/html\n\n";
print "<h2>This is first!</h2>\n"; 

Where to store this script by which extention either .cgi or .pl? What are the necessary should follow to execute this script . Please let me know I know this is very basic question. I could not found any better link on google so i posted.

2 Answers 2

3

This process is described in detail many many places. To summarize:

  1. You configure apache to use CGI and place your script in an appropriate place, as explained here.

  2. You check the server logs to find out what went wrong when your script is run. How to find and configure the logs is explained here.

  3. You change your script to deal with problems. Apache doesn't cache CGI, so you should not have to restart the server.

A few quick points:

  • perl -w and use warnings are redundant; the latter is preferred.
  • The HTTP header ends with a double CRLF sequence: \r\n\r\n. I believe \n\n will produce that on windows only, but since this is a *nix forum, I presume that's not where apache is running. You'll need \r\n\r\n or that script will output nothing in a browser and probably not produce an error in the logs, either.
1

I believe more than one way to do this with Apache exists. Here's my way:

Add a <Directory> section to httpd.conf (and even the location of that varies, my Arch linux server has it in /etc/httpd/conf/).

<Directory "/srv/http/stratigery/cgi-bin">
    Options Indexes FollowSymLinks ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

The directory name ("/srv/httpd/stratigery/cgi-bin") should not be in your DocumentRoot directory. The directory should exist and have 755 permissions.

The "ExecCgi" option is the important thing for CGI-BIN program execution in this case. The script name doesn't matter. What matters is that the script lives in the directory you named, and that it has user, group and other execute permission.

Stop and start Apache (apachectl stop, apachectl restart, probably). The ask for your script in a browser: http://whatever.hostname/cgi-bin/scriptname.

If that doesn't work, look in the Apache log file, likely /var/log/httpd/error_log.

Not the answer you're looking for? Browse other questions tagged .