I’m trying to do some work with a Perl app on my Powerbook but I was unable to get any Perl scripts to execute from my local server. At first, I was getting just the source of the Perl files spit back at me. I followed a few tutorials about getting /etc/httpd/httpd.conf set up, but then I kept getting 403 Forbidden errors when I tried to access .pl or .cgi files in my browser. I checked /var/log/httpd/error_log and saw:
[Thu Mar 22 10:55:17 2007] [error] [client 127.0.0.1] Options ExecCGI is off in this directory: /Users/sarah/Sites/test.cgi
I thought to myself, “B.S.! ExecCGI is on for that directory!” Sure enough, in my httpd.conf file, I had:
<Directory /Users/*/Sites>
AllowOverride FileInfo AuthConfig Limit
Options ExecCGI MultiViews Indexes SymLinksIfOwnerMatch Includes
DirectoryIndex index.htm index.html index.cgi
<Limit GET POST OPTIONS PROPFIND>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS PROPFIND>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
I had restarted Apache with sudo apachectl graceful, so what was up? Then I noticed something else in error_log:
Processing config directory: /private/etc/httpd/users/*.conf
Processing config file: /private/etc/httpd/users/sarah.conf
What was this /private/etc/httpd/users/sarah.conf that it was talking about? I had never created this file. I checked and it certainly existed. It also had an Options line without ExecCGI—bingo! I simply removed the file because it was just redefining what I had already specified in httpd.conf for Users/*/Site directories (shown above). I then restarted Apache and voila, my scripts worked. :) I can only assume something auto-generated that file, because it certainly wasn’t me.
Other things to check if you’re still seeing the source of your scripts or getting a 403 error:
- Is your script executable? Chmod it to 755 to be sure.
- Ensure these lines are uncommented in your /etc/httpd/httpd.conf (or whatever your Apache config file is):
LoadModule cgi_module libexec/httpd/mod_cgi.soLoadModule perl_module libexec/httpd/libperl.soAddModule mod_cgi.cAddModule mod_perl.cAddHandler cgi-script .cgi .pl
- Be sure to restart Apache after making any config file changes. You can do this via Terminal with the command
sudo apachectl graceful, which will prompt you for your password, or via System Preferences > Sharing, where you Stop “Personal Web Sharing” and Start it again.
2 Comments
Thanks so much for the excellent posting. Even though I followed your instructions I couldn’t get past the Forbidden error until I put the conf statements in my personal conf file. Then, with a server restart everything happened. Sweet!
Thanks! I did all the things described in your post with no success, until I saw “sudo apachectl graceful” whereas I was doing the old “httpd restart”
Bleh.