While configuring with apache and perl cgi scripts, don’t know why index.cgi/index.pl are displayed as plain text instead of executing them.
When browser is printing code of script that means it’s unable to find the application to run the script. Below two lines should be your first steps to solve this. AddHandler will make sure files ending with .cgi and .pl to be treated as cgi scripts. And +ExecCGI option will allow to execute the script. Also make sure your script is pointing to correct perl binary location.
AddHandler cgi-script .cgi .pl Options FollowSymLinks +ExecCGI
Also There are some mistakes/misconfiguration points in your httpd.conf
- Alias line should point to cgi-bin directory where your cgi scripts are present.
ScriptAlias /cgi-bin/ “D:\webserver\cgi-bin”
- For same cgi-bin directory following configuration should be in
httpd.conf. You should replace your<Directory "D:\webserver">part with below.
<Directory "D:\webserver\cgi-bin" /> AddHandler cgi-script .cgi .pl Options FollowSymLinks +ExecCGI AllowOverride None </Directory>
- Try running your cgi script from command line like below. It should print or run from command line first.
perl test.cgi
- Make sure you have read-write recursive permissions to
cgi-bindirectory and your cgi script. And also you can create directory or file with write permissions. If not create acgi-bindirectory at some other place where you can have write permissions and provide rather its path inaliasanddirectoryattributes inhttpd.confinstead. - Check apache error log for exact error message every time you run into apache conf issues. It will give you good insight into the problem.
Also this link should help you.
(Extra comment, not by the original answerer: You may also need to enable the cgi module. For me, the final step to getting cgi to work on a fresh install of Apache 2 was sudo a2enmod cgi. Before I did that, the website simply showed me the contents of the script.)
sudo a2enmod cgi