Perl Apache : Perl script displayed as plain text
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-bin
directory and your cgi script. And also you can create directory or file with write permissions. If not create acgi-bin
directory at some other place where you can have write permissions and provide rather its path inalias
anddirectory
attributes inhttpd.conf
instead. - 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
change new version of apache : Options +FollowSymLinks +ExecCGI
The directory/location/file doesn't have the right handler associated with it, or doesn't have the ExecCGI
option enabled. See Apache Tutorial: Dynamic Content with CGI.
on mac os x 10.8
i had to do this
<Directory />
Options FollowSymLinks +ExecCGI
AllowOverride None
</Directory>
and
uncomment this
#AddHandler cgi-script .cgi .pl