<-
Apache > HTTP Server > Documentation > Version 2.4 > How-To / Tutorials

Apache Tutorial: Dynamic Content with CGI

Available Languages:  en  |  es  |  fr  |  ja  |  ko 

Support Apache!

See also

top

Introduction

The CGI (Common Gateway Interface) defines a way for a web server to interact with external content-generating programs, which are often referred to as CGI programs or CGI scripts. It is a simple way to put dynamic content on your web site, using whatever programming language you're most familiar with. This document will be an introduction to setting up CGI on your Apache web server, and getting started writing CGI programs.

top

Configuring Apache to permit CGI

In order to get your CGI programs to work properly, you'll need to have Apache configured to permit CGI execution. There are several ways to do this.

Note: If Apache has been built with shared module support you need to ensure that the module is loaded; in your httpd.conf you need to make sure the LoadModule directive has not been commented out. A correctly configured directive may look like this:
LoadModule cgid_module modules/mod_cgid.so
On Windows, or using a non-threaded MPM like prefork, A correctly configured directive may look like this:
LoadModule cgi_module modules/mod_cgi.so

ScriptAlias

The ScriptAlias directive tells Apache that a particular directory is set aside for CGI programs. Apache will assume that every file in this directory is a CGI program, and will attempt to execute it, when that particular resource is requested by a client.

The ScriptAlias directive looks like:

ScriptAlias "/cgi-bin/" "/usr/local/apache2/cgi-bin/"

The example shown is from your default httpd.conf configuration file, if you installed Apache in the default location. The