Run CGI Scripts in an Apache Content Directory

From LinuxServerTech

Jump to: navigation, search


Set Apache Directory to Execute CGI Scripts and server standard HTML

In apache2.conf (or a domain), you will need to add the following (assume /common-cgi is the directory you want to use:

Alias /common-cgi/ /home/http/common-cgi/
<Directory "/home/http/common-cgi">
AllowOverride None
AddHandler cgi-script .cgi .pl .sh
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

The Alias line simply sets up common-cgi to be an alias inside the web root to a different directory, so when they say http://domain/common-cgi, it is actually looking for the absolute directory.

Now, for the directory, you will need to set up some information. The important thing here is the AddHandler, which tells it that files ending in .pl, .sh and/or .cgi are cgi scripts and should be treated as such, thus executed by the OS and the output sent to the browser via Apache. The Options ExecCGI allows that to happen in this directory. Note: if a global addhandler for the correct extensions is already set, you do not need to worry about the AddHandler line here.