Overview
Common Gateway Interface (CGI) is an important World Wide Web technology that enables a client web browser to request data from a program executed on a webserver. CGI specifies a standard for passing request data between a web server and the program used to service that request. CGI scripts are often preferred by web developers because of their speed and their minimal resource requirements. CGI scripts on DreamHost can be written in all of the languages commonly used with CGI (Perl, Python, Ruby, even shell scripts), as long as you have an interpreter for that language to compile.
Running a CGI script at DreamHost
To run, copy the script to a web-accessible directory. For example:
/home/username/example.com/cgi-bin
Change username to your Shell user and example.com to your website. You don't have to put your CGI scripts in a cgi-bin directory, as CGI scripts can run from any directory within your domain on DreamHost. The server understands several file extensions (e.g., .pl), but if you see the source code of your script instead of the result of its execution, try using the generic extension .cgi.
If you get a "500 Internal Server Error", you may need to change the permissions of the file:
[server]$ chmod 755 script.cgi
Running a CGI script without a .cgi extension
If you wish to install a CGI script without the .cgi extension, simply use a <Files> directive in your .htaccess. For example, if you wish to have a cgi-bin directory, create a file named .htaccess inside of it, and then insert the following:
<Files *> SetHandler cgi-script </Files>
Once you add this directive, all files within the directory will run as CGI scripts.
Examples of CGI Scripts
Perl
#!/usr/bin/perl use strict; use CGI; my $q = CGI->new; print $q->header(); print "Hello, world!";
Python
#!/usr/bin/python print "Content-type: text/html" print print "Hello, world!"
Ruby
#!/usr/bin/ruby require 'cgi' cgi = CGI.new cgi.out{ 'Hello, world!' }
Shell Script
#!/bin/sh echo "Content-type: text/html" echo echo "Hello, world!"
suEXEC
suEXEC is enabled for all DreamHost users and cannot be disabled. Because of this, some features, such as the SetEnv directive in .htaccess files, won't work as expected. See the suEXEC page for workarounds and more details.
Troubleshooting CGI issues
View the following article for help with troubleshooting CGI issues: