Why is my Perl CGI script showing as plain text in the browser?
I have been playing around with my Mac server and now I am trying to create a simple html form and perl script that outputs data. I have / Library / WebServer / Documents symbolically linked to ~ / Sites /, so I have index.html and display.cgi. But when I hit submit, the perl file is only displayed as text. Any cgi file I have is not executed, it just displays as text. What am I doing wrong? Thank.
source to share
If your server is not specifically configured to run perl scripts in a folder /Library/WebServer/Documents
, you will have to put them in /Library/WebServer/CGI-Executables
. (And then access them from the path /cgi-bin/
in the url, for example http://localhost/cgi-bin/display.cgi
.)
Once you have done that, make sure you set permissions on the Perl script in order for it to execute. To do this, go to the contained directory in a terminal and enter chmod a+x display.cgi
.
Also make sure the first line of the script (the shebang line) has the correct perl path. On my Mac Perl is in /usr/bin/perl
, but if you want to check for yourself, run the command which perl
.
source to share
To answer another question:
To use CGI scripts from outside the directory cgi-bin
, you will probably have to dive into configuration files. The main one is the /private/etc/httpd/httpd.conf
one with which you will have to use the terminal, because the directory /private/
is hidden by default.
Alternatively, you can create a file .htaccess
in the directory where you want to place the script. This man page should help you figure out what to put in there. Note that the Apache manual will not have any Mac-specific information in it, as it is also used for other operating systems.
source to share