= CGI = '''Common Gateway Interface''' is a specification for web servers to interact with scripts or binaries. It launched a family of specifications, such as '''FastCGI''' and '''WSGI'''. <> ---- == History == The '''Common Gateway Interface''' was designed to enable dynamic web pages ''without'' requiring web servers to be highly extensible. (In comparison, [[Apache]] had modules that enabled direct execution of scripts, such as `mod_php` and `mod_perl`.) The web server spawns a process to handle a request, passing information by the environment. By convention, CGI scripts are typically placed in a `cgi-bin` folder under the web root. For a variety of performance and security reasons, CGI scripts are no longer used. '''FastCGI''' is a comprehensive upgrade of the specification that ''is'' still used. The most significant change is that spawned processes run continuously to handle multiple requests, rather than exiting upon completion of a single request. Communication between processes is handled by ([[Protocols/TCP#Sockets|TCP]] or [[Linux/Networking#Unix_Sockets|Unix]]) sockets. Language-specific frameworks have also emerged as a successor, such as [[Python|Python's]] '''Web Server Gateway Interface'''. In any case, a CGI program accesses system and connection information by way of environment variables, such as `$DOCUMENT_ROOT` (the web root), `$SCRIPT_FILENAME` (the CGI script's filename which should be under the web root), and `$QUERY_STRING` (the requested URI parameters). ---- == FastCGI == Options for FastCGI servers include: * [[Apache/FastCGI#Mod_fcgid|mod_fcgid]] * [[PHP/FPM|PHP-FPM]] * [[Fcgiwrap|fcgiwrap]] ---- == Web Server Gateway Interface == The [[Python]] project designed a succor specification called Web Server Gateway Interface, or WSGI. While there is a [[https://docs.python.org/3/library/wsgiref.html|reference implementation]] (`wsgiref`), the following are far more commonly used: * [[Python/Django|Django]] * [[Python/Flask|Flask]] * [[Python/Gunicorn|Gunicorn]] * [[Python/Uwsgi|uWSGI]] ---- CategoryRicottone