Problems with Perl & CGI scripts and permissions
1. How do I enable CGI or perl script execution in directories other than the ScriptAlias?
This is undoubtedly the number one question people ask about Apache. The answer, not surprisingly is quite simple...
To persuade Apache to execute scripts in other locations, such as in directories where normal documents may also live, you must tell it how to recognize them - and also that it's okay to execute them. For this, you need to use something like the AddHandler directive.
In the specific section of your server's httpd.conf configuration file, add or uncomment the following line:
AddHandler cgi-script .cgi
Add the .pl extension to the end of this line if you want to use .pl extensions
If mod_perl is installed make sure the following is not commented out:
<IfModule mod_perl.c>
Alias /perl/ /home/httpd/perl/
<Location /perl>
SetHandler perl-script
PerlHandler Apache::Registry
PerlSendHeader On
Options +ExecCGI
</Location>
</IfModule>
The server will then recognize that all files in that location (and its logical descendants) that end in ".cgi" or ".pl" are script files, not documents.
So if you put this in a VirtualHost directive (assuming this was where you wanted to be able to run the cgi script) you'd be hot on the trail of a solution! Just make sure that the directory location is also covered by an Options declaration that includes the ExecCGI option.
There are also permissions issues associated with scripts and SWS. For a script to run with SWS the permissions on the script must be 0755 as well as the entire path to the file. You must also make sure that the owner of the directory and the owner of the file are the same.
One addendum to all of this is that if you're running SWS 3.0 there is a small bug in the
httpd.conf file. This bug affects the servers ability to glob the path for public_html
directories.
Here's the fix:
Find this line:
<Directory /*/public_html>
and change it to this:
<Directory /home/*/public_html>
2. What does it mean when my CGIs fail with "Premature end of script headers" or "Internal Server Error"?
Quite simply it means your script is not working correctly and it did not complete the action it was supposed to. Why does this happen? Well the most common reason is that the script does not have the proper permissions. "Wait a minute!", you say, "...how can that be? I tested it and it worked fine on the command line!". Well never fear... what's probably happening is that when you run it one the command line that script has the same permissions you do, but when you run it in the server, it's permissions are equal to the permissions that the server has. One other issue which may arise is that the file you want to execute must be owned by the same user who owns the directory. To test this make two identical scripts in the directory being served. Leave one with the proper permissions and change the other to be owned by root. Something to think about isn't it?
3. I've just created a really cool perl script! I ftp'd it to my site and I've got it in ScriptAlias but it won't run. What's wrong?
Did you set the "x" bit on that script after you ftp'd it? (IOW did you forget to make it executable?)
4. Why do I keep getting "Method Not Allowed" for form POST requests?
Is the file you're trying to post to an html file or a cgi script? Which does the server think it is? If it's an html file that's a no-no. The server is not going to allow that.