Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

closed as off-topic by goldilocks, slm, Anthon, Zelda, Timo Feb 10 at 15:14

  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

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.
share|improve this answer

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.