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] 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 <strong>ExecCGI</strong> MultiViews Indexes SymLinksIfOwnerMatch Includes
    DirectoryIndex index.htm index.html index.cgi
        Order allow,deny
        Allow from all
        Order deny,allow
        Deny from all

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 tutorials (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.so
    • LoadModule perl_module libexec/httpd/libperl.so
    • AddModule mod_cgi.c
    • AddModule mod_perl.c
    • AddHandler 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.