Book a call Free rebuild
Home/Glossary/Hosting/Common Gateway Interface (CGI)

Common Gateway Interface (CGI)

May 20, 2023 Updated November 16, 2026 2 min read

Hosting glossaryThe Common Gateway Interface (CGI) is an early standard for how a web server runs an external program to build a page for a request. Modern stacks such as PHP-FPM replaced it.

Before CGI, web servers could only hand out files that already existed. The Common Gateway Interface, developed at NCSA in the early 1990s and later documented as CGI/1.1 in RFC 3875, defined a simple contract that let a server run a program instead and send back whatever that program printed. It is how the first search boxes, guestbooks, and contact forms worked, and the reason many hosting accounts still have a cgi-bin folder.

How it works

  1. A request arrives for a URL mapped to a CGI program, such as /cgi-bin/search.pl.
  2. The server starts the program as a new process and passes it details of the request in environment variables, such as REQUEST_METHOD, QUERY_STRING, and REMOTE_ADDR. For a POST request, the form data arrives on standard input.
  3. The program writes HTTP headers, a blank line, and then the page body to standard output.
  4. The server sends that output to the browser, and the process exits.

Because the contract is just environment variables and standard input and output, a CGI program can be written in almost any language: Perl was the classic choice, but C, shell scripts, and Python all work.

Why it was replaced

Starting a fresh process for every request is slow and memory-hungry, and it gets worse as traffic grows. Successors keep the program running between requests:

  • FastCGI keeps a pool of long-running worker processes that the web server talks to over a socket. PHP-FPM, the usual way to run PHP behind NGINX and increasingly behind Apache, is a FastCGI process manager.
  • Embedded modules such as Apache's mod_php run the language inside the web server itself.
  • Language-specific interfaces such as Python's WSGI and Ruby's Rack follow the same idea of a standard gateway between server and application.

CGI and WordPress

WordPress is PHP, and on a modern host it runs through PHP-FPM, LiteSpeed's LSAPI, or a similar persistent handler. Some hosting control panels still let you choose the PHP handler, and plain CGI is usually the slowest option on the list; it is rarely the right choice for a WordPress site.

Security

Old CGI scripts are a known risk. Because CGI passes request data to programs through environment variables, the 2014 Shellshock bug in the Bash shell could be exploited through CGI scripts on unpatched servers. If a site still has scripts in cgi-bin that nobody maintains, removing them is the safest fix.

Source: RFC 3875, The Common Gateway Interface (CGI) Version 1.1.

HostList

The hosting directory with no paid rankings.

Compare 30,000+ web hosts and MSPs across 120+ countries, ranked by HRI, an independent 0 to 100 rating built from verified data. Find your perfect web host.