Enabling CGI in Apache virtual hosts

Add this to the Apache configuration:

ScriptAlias /cgi-bin/ "/var/www/html/cgi-bin/"
<Directory "/var/www/html/cgi-bin">
        Options +ExecCGI
        AddHandler cgi-script .cgi
</Directory>

Reload Apache and throw this in as test.cgi into your cgi-bin directory:

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";

Do not omit the content-type on your perl scripts. If you do, Apache will throw a random 500 Internal Server Error and it won't log anything about it.

Printed from: http://rackerhacker.com/2007/01/26/enabling-cgi-in-apache-virtual-hosts/ .
© Major Hayden 2012.

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this