apache configration

cgi scripts

These can be written in any language, but in most cases perl is used. See 'testing' to get an idea of the requirements a cgi script must meet independant of its language. In order to run scripts apache has the mod_cgi script, which can be an external module or compiled in. If it is an external module it must be activated like so:


LoadModule cgi_module modules/mod_cgi.so # do not mix this up with mod_cgid

We also need to configure where cgi scripts are allowed to be executed. the criteria can be a path or a file extension and if you have an AllowOverride All directive in your httpd.conf you can also use a .htaccess-file to tell apache which files are cgi scripts. In the first case this is done by defining a ScriptAlias, a path in which only cgi-scripts are allowed to be, because anything will get exected. I do not like this at all. You better specify AddHandler cgi-script pl cgi in a .htaccess in the folder where your scripts are or in the main configuration for that folder, which might look something like this:


Alias /public "/mnt/zpool/data/public"

       Options Indexes FollowSymLinks MultiViews ExecCGI
       AllowOverride All
       Order allow,deny
       Allow from all


Apache expects cgi-scripts to return a http header. To test your configuration you can write a program in any language to return:

content-type: text/html\n\n
this is a test

and append its extension to the list of cgi scripts, e.g. using a minimal .htaccess-file:


Options Indexes ExecCGI
AddHandler cgi-script pl cgi

I like having these scripts laying around for testing after a set up:

# test.pl
print qq[content-type: text/htmlnn];
print qq[this is a test];
<!-- test.php -->
// test.c

#include <stdio.h>
int main()
  puts("content-type: text/htmlnn");
  puts("this is a test");

# gcc -Wall -o test.cgi test.c
# chmod g-w test.cgi
# if you are using SELinux you might also be interested in setting:
# chcon unconfined_u:object_r:httpd_sys_content_t:s0 test.cgi