.CGI

CGI File

Common Gateway Interface Script
Ask a question
QUICK ANSWER

A CGI file is a Common Gateway Interface script - a program a web server runs to generate a page dynamically (form handlers, counters, old guestbooks). It is usually plain-text source code, most often Perl or Python, so you open it in any code editor to read or edit it. It does not run in your browser: to execute it you put it in the server's /cgi-bin/ directory, make it executable, and the server runs it when a browser requests that URL.

Developer: NCSA / CGI community (RFC 3875 documents the interface) Category: Executable Files Open standard MIME: application/x-httpd-cgi
OPENS ON Windows macOS Linux
Related: .APK · .EXE · .VBS · .JAR

On this page

19k+ extensions indexed
Last reviewed Jul 10, 2026

Not sure what your file is?

Drop any file into our identifier - we read just the first bytes to name the format.

Identify a file

What is the CGI file format?

The .cgi extension stands for Common Gateway Interface - a standard approach to generate web applications and dynamic content on web pages. The .cgi extension, when applied on a web server, provides an interface between executable programs and the web server that generates the website content. All such programs are called CGIs or CGI scripts.

These files are generally written using a scripting language such as Perl, Python, or shell script, though a .cgi file can equally be a compiled binary (for example, a C program). The extension itself says nothing about the language inside - the shebang line at the very top of the script, such as #!/usr/bin/perl or #!/usr/bin/python3, tells the web server which interpreter to invoke.

A CGI script runs on the server once per incoming HTTP request. It reads request data from environment variables (QUERY_STRING, REQUEST_METHOD, CONTENT_TYPE) and accepts POST body data via stdin, then writes an HTTP response - headers followed by body content - directly to stdout. To function, the file must be placed in a CGI-enabled directory (traditionally /cgi-bin/) and have the executable permission set on the server.

.cgi is an interface standard, not a programming language. Several other file formats share the .cgi extension: .pl, .py, or .sh scripts are often renamed to .cgi so the web server routes them through the CGI mechanism. Because CGI spawns a new process for every request it is slow at scale, and it has largely been superseded by FastCGI, mod_php, WSGI, and modern application servers - though it remains supported on most web servers today.

Security & safety

RISK: MEDIUM

Reading a .cgi in a text editor is safe - it won't run by being opened. The risk is in EXECUTION on a server: CGI scripts run with the server's privileges and historically are a major web-vulnerability surface (the 2014 Shellshock bug was exploited largely through CGI shell scripts; poorly written CGIs enable command injection, path traversal and arbitrary code execution). Never deploy a downloaded .cgi you don't understand, keep interpreters and the server patched, restrict /cgi-bin/ permissions, and prefer FastCGI/app-server alternatives for new work. Treat unknown CGI source as untrusted code to be reviewed before running.

Format details

in a nutshell
FULL NAMECommon Gateway Interface Scriptaka CGI script, CGI program
DEVELOPERNCSA / CGI community (RFC 3875 documents the interface)since 1993 (NCSA HTTPd); formalized as CGI/1.1 in RFC 3875 (2004)
MIME TYPEapplication/x-httpd-cgi
TYPEServer-side executable script (usually plain-text source; sometimes a compiled binary)
STANDARDOpen · royalty-free
This extension is also used by…
  • EToys / niche app data using .cgi - A few unrelated applications have reused .cgi for their own data files; on a web server a .cgi is almost always a gateway script.

Programs that open CGI files

Windows3 apps
Notepad Open-source Open the .cgi to read/edit the source with syntax highlighting (Perl/Python/shell). The right tool to inspect or modify a script.
Visual Studio Code Free Open the .cgi for full editing with language extensions, linting and Git; the modern editor for web scripts.
Apache HTTP Server (to run it) Open-source To EXECUTE a CGI: place it in a CGI-enabled directory (mod_cgi, /cgi-bin/), ensure the interpreter is installed and the file is executable, then request its URL.
macOS2 apps
BBEdit Freemium Open the .cgi to read/edit the source on macOS.
Visual Studio Code Free Edit the .cgi with language support and run it via a local Apache/Python http server.
Linux2 apps
Any text editor (gedit, Vim) Open-source Open the .cgi to read/edit the script source.
The interpreter / web server Open-source Run directly with its interpreter (perl script.cgi) for testing, or serve it via Apache mod_cgi / a CGI-capable server. Make it executable with chmod +x.

Technical details

deep spec
MIME typeapplication/x-httpd-cgi
Alternate MIME typestext/plain, application/octet-stream
File encodingPlain text (ASCII/UTF-8) for scripts; native binary for compiled executables
File signatureNo fixed magic bytes - text scripts open with a shebang line (#!/usr/bin/perl, #!/usr/bin/python3, #!/bin/sh, etc.); compiled CGI binaries carry the platform executable header (ELF on Linux, MZ on Windows)
Execution modelWeb server forks a new OS process per HTTP request to run the script or binary; process exits after the response is sent
Input mechanismRequest data delivered via environment variables (QUERY_STRING, REQUEST_METHOD, CONTENT_TYPE, HTTP_* headers); POST body passed via stdin
Output mechanismScript writes HTTP response headers (Name: value lines) followed by a blank line and the response body directly to stdout
Required deploymentFile must reside in a CGI-enabled directory (conventionally /cgi-bin/) with the executable bit set; web server user needs read and execute permission
Typical scripting languagesPerl, Python, Bash/shell, Ruby, C (compiled to a native binary)
Typical file size1 KB - 100 KB for text scripts; larger for compiled binaries
CompressionNone within the file itself; the HTTP response body may be gzip-compressed separately by the script or server
Platform supportLinux, Unix, macOS, Windows - any OS running a CGI-capable web server
Common web serversApache HTTP Server, Nginx (via FastCGI wrapper), lighttpd, Microsoft IIS
Performance characteristicSlow at scale - each request spawns and destroys a new process; superseded by FastCGI, WSGI, and ASGI for high-traffic deployments
Security considerationScript source is readable on disk; protect with strict file permissions and avoid exposing the CGI directory via a direct URL outside the designated /cgi-bin/ path
Released1993 (NCSA HTTPd); formalized as CGI/1.1 in RFC 3875 (2004)
Latest versionCGI/1.1 (RFC 3875, October 2004)
Open standardYes · royalty-free
Specificationwww.rfc-editor.org

CGI conversions

Community Q&A

asked by users
Ask a quick question
Get help from people who work with CGI files. Be specific - include your system and software version.
No account needed · answers usually within a day

No questions yet - be the first to ask about CGI files.

Frequently asked questions

What is a .cgi file?
A Common Gateway Interface script - a program a web server runs to generate a page dynamically (forms, counters, old guestbooks). It's usually plain-text source (often Perl or Python) and runs on the server, not in your browser.
How do I open a .cgi file?
To read or edit it, open it in a code editor (Notepad++, VS Code, BBEdit) - it's typically text source. To RUN it, put it in the server's /cgi-bin/, make it executable, and request its URL; CGIs don't run by double-clicking.
Why does my browser show the CGI code instead of running it?
The server isn't configured to execute CGI in that location: CGI handling (mod_cgi) is off, the directory isn't CGI-enabled, the file lacks execute permission, or the shebang/interpreter is wrong. Place it in /cgi-bin/ and fix permissions.
What language is a .cgi written in?
The extension doesn't say - check the first line. A shebang like #!/usr/bin/perl, #!/usr/bin/python3 or #!/bin/sh tells you the interpreter. Some CGIs are compiled C binaries instead of readable source.
Is CGI still used?
It still works and is supported, but it's legacy: starting a process per request is slow, so most sites moved to FastCGI, mod_php, WSGI/Rack app servers and modern frameworks. You'll still see .cgi in old scripts and some hosting panels.
Are .cgi files dangerous?
Opening one in an editor is safe. Running an untrusted CGI on a server is risky - CGIs run with server privileges and have a history of serious flaws (e.g. Shellshock). Review any downloaded CGI before deploying and keep your server patched.

References

1RFC 3875 - The Common Gateway Interface (CGI) Version 1.1www.rfc-editor.org
2Wikipedia - Common Gateway Interfaceen.wikipedia.org

Keep exploring

across the database

Top extensions this week

1.AQQAQQ Instant Messenger File
2.MDMarkdown Document
3.CRDOWNLOADChrome Partial Download File
4.BINCD/DVD Disc Image (BIN/CUE)
5.PARTPartial Download File
6.RPMSGRestricted Permission Message
7.NOMEDIAAndroid No-Media Marker File
8.EXEWindows Executable (Portable Executable)
9.AVIFAV1 Image File Format (AVIF)
10.ICSiCalendar data file

Related extensions

.APKAndroid Package
.EXEWindows Executable (Portable Executable)
.VBSVBScript file (Visual Basic Script)
.JARJava Archive
.EX4MetaTrader 4 Compiled Program (Expert Advisor / Indicator / Script)
.APPXMicrosoft Windows App Package (AppX)

Free file tools

An in-browser file identifier and image converter - everything runs on your device.

Open the toolbox

Browse file extensions A-Z