How do I make apache run a cgi instead of showing the text?

Did you load the mod_cgi module? You can see if the directory /etc/apache2/mods-enabled/ has a symlink cgi.load. If there is no such symlink, you can create it by running

sudo a2enmod cgi

and then restart Apache:

sudo service apache2 restart

You can run man a2enmod to see what a2enmod does.


When installing Apache 2.4 I had a number of issues to solve and also had the same issue with text showing instead of running the cgi. The solution is not the same as above, which is the solution for Apache 2.2

First, you need to download the 2.4 gz file and unpack. If you try to compile, it will complain the APR is not found, since it is no longer included. You need to download the apr and apr-util files from Apache and unpack them into the directory you are compiling Apache into the subdirectory called srclib, so your path would be ./httpd/srclib/apr and ./httpd/srclib/apr-util. You must also remove any version numbers from the directory name.

cd to your /path/httpd directory and the compile with

$ ./configure --with-included-apr

Your config will default to PREFIX=/usr/local/apache2

$ make

$ make install

$ vi PREFIX/conf/httpd.conf

You will need to edit your httpd.conf file to get your cgi's to run

In my case I did the following:

change Listen 80 to Listen 127.0.0.1:80

activate the line:

LoadModule cgid_module modules/mod_cgid.so

changed SeverName to:

ServerName 127.0.0.1:80

changed the paths in DocumentRoot and <Directory> to suit my system

changed the path in ScriptAlias

enabled the line Scriptsock cgisock

changed the path in <Directory> after the ScriptAlias to suit my system

enabled the line AddHandler cgi-script .cgi

saved the changes and started Apache with:

$ /usr/local/apache2/bin/apachectl -k start

Hope this helps anyone struggling with this ;)