I have a website up and running on the Apache webserver, but the CGI scripts in /Library/WebServer/CGI-Executables will not run. Instead, the text of the file loads in the browser instead.

I made the following changes to httpd.conf:

  1. Added the following line to the LoadModules group:

    LoadModule cgi_module /usr/libexec/apache2/mod_cgi.so

  2. Uncomment the following line (by removing the #):

    AddHandler cgi_script .cgi

  3. Added this to the virtual host file for the specific site:

<VirtualHost *:81>
    DocumentRoot "/Library/WebServer/Documents/"
    ScriptAlias /cgi-bin/ "/Library/WebServer/CGI-Executables/"
    <Directory "/Library/WebServer/CGI-Executables/">
    AllowOverride none
    Options +ExecCGI
    AddHandler cgi-script .cgi

I am able to run the Perl scripts from the command line without an issue.

Note: this is on High Sierra.

  • I'm voting to close this question as off-topic because it seems to be about web development. – Jaime Santa Cruz Apr 10 at 21:54
  • 1
    @Jaime This question is not at all about web-development. It is how to install web site programs on your Mac. It could be for example an image gallery program, GitWeb, MovableType, or something different. This is just about how to configure the built-in webserver that comes with macOS. – jksoegaard Apr 10 at 23:50
  • 1
    Thanks for the edit. This absolutely is on topic as long as the host OS is mac or the hardware is mac or the client is mac. It could be on topic other places too, but we wouldn’t migrate away from here or close unless it was requested by OP and on topic elsewhere. – bmike Apr 11 at 1:29
  • @jksoegaard my bad – Jaime Santa Cruz Apr 11 at 2:10

Most probably you're running into one of the following problems:

Wrong handler name: In your question, you wrote that you had the following line:

AddHandler cgi_script .cgi

The underscore is supposed to be a hyphen here, so change that to:

AddHandler cgi-script .cgi

Wrong file extension: Your have specified in your configuration that your Perl scripts are named something.cgi. Some actually have their files named something.pl instead. If that is the case for you, you'll need to extend both of your AddHandler lines to the following:

AddHandler cgi-script .cgi .pl

Permissions: The Perl scripts needs to have the executable permission bit set in order to be executed as a CGI-script. This means that you have to run a command such as this:

chmod a+x /Library/WebServer/CGI-Executables/yourscript.cgi

You would have to replace "yourscript.cgi" with the actual filename of your script.

Restart needed: You need to ensure that the Apache webserver program is actually reloaded or restarted after you change your configuration files. Do this by running the following command:

sudo apachectl -k restart
  • Thanks for this info. So, I followed your instructions and was able to designate a folder within the website for script execution and it worked. However, I want to run them from the CGI-Executables folder as mentioned above. I enable this with [ScriptAlias /cgi-bin/ "/Library/WebServer/CGI-Executables/"] in the vhosts files but I get the error in the log: [authz_core:error] [pid *] [client *] AH01630: client denied by server configuration: /Library/WebServer/CGI-Executables/. It seems like ScriptAlias isn't doing what it's supposed to...? – M Smith Apr 11 at 13:56
  • So I solved it! I added this after the ScriptAlias command in the vhosts file: <Directory "/Library/WebServer/CGI-Executables/"> AllowOverride none Options ExecCGI AddHandler cgi-script .cgi Require all granted </Directory> – M Smith Apr 11 at 14:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .