CGI scripts won't execute on website 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:


Added the following line to the LoadModules group:

LoadModule cgi_module /usr/libexec/apache2/mod_cgi.so
Uncomment the following line (by removing the #):

AddHandler cgi_script .cgi
Added this to the virtual host file for the specific site: 



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



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

Note: this is on High Sierra.
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