I've installed apache2 on Ubuntu 11.04, and localhost is working. I created a simple printenv.pl script and put it in the following directory

$ mv printenv.pl /usr/lib/cgi-bin/
$ chmod +rx /usr/lib/cgi-bin/printenv.pl

However when I go to, I get a 500 Internal Server Error

I checked the error log at /var/log/apache2, and this is what it says:

[Mon Oct 24 11:04:25 2011] [error] (13)Permission denied: exec of '/usr/lib/cgi-bin/printenv.pl' failed
[Mon Oct 24 11:04:25 2011] [error] [client] Premature end of script headers: printenv.pl

Any suggestions on how I can fix this and run CGI scripts on my localhost?


I had this problem as well. It turned out that I had set the .pl files permissions to 775. Apache does not allow user writable. Try changing your .pl file permissions to 755.

If that isn't it, check your web site permission settings in /etc/apache2/sites-available.

| improve this answer | |

I had this exact problem (with the exact same paths, directories, permissions, etc.) just a little while ago, and all of a sudden understood what I read somewhere in the Apach2 documentation about a week ago.

That is this - everything you have set up so far is fine, but for security reasons, apache will not run any file (CGI, Perl, C, etc.) unless its write permission (w) is removed completely.

Make the permissions look like this: -r-xr-xr-x

Then it should work just fine. Hope this helps, let me know if it still doesn't work.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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