CGI according to the definition of Baidu Encyclopedia, as follows:
CGI is the specification of external programs when the Web server is running, and programs written by CGI can extend server functionality. CGI applications can interact with the browser, and data can be obtained from the database server by communicating with external data sources such as database servers through the database API. When formatted as an HTML document, it is sent to the browser, or the data obtained from the browser can be placed in the database. CGI is supported on almost all servers, and CGI can be written in any language, including popular C, C + +, VB, and Delphi. CGI is divided into two types of standard CGI and indirect CGI. Standard CGI uses command line arguments or environment variables to represent detailed server requests, and the server communicates with the browser using standard input and output methods. Indirect CGI, also known as buffered CGI, inserts a buffer between the CGI program and the CGI interface, and the buffer program communicates with the CGI interface using standard input and output. The above paragraph of the first contact with CGI, may not understand what the meaning, the following example is easy to understand. In Apache, for example, there is a folder in the root directory for/cgi-bin, which searches for CGI in configuration file httpd.conf
<ifmodule alias_module> scriptalias/cgi-bin/"/usr/local/apache/cgi-bin/" </ifmodule><ifmodule cgid_module> #Scriptsock cgisock</ifmodule><directory "/usr/local/apache/cgi-bin" > allowoverride all Options None Require all granted</directory>
Enter the Cgi-bin directory and create a file with a file name of index.cgi and a. cgi file name extension, which is the same as the php file extension. php.
The contents of index.cgi are as follows:
#!/bin/bash#index.cgiecho "Content-type:text/html;charset=utf-8" Echoecho "Hello World"
Then visit localhost/cgi-bin/index.cgi in the browser and you will see the results as follows:
Then change the contents of the index.cgi:
#!/bin/bash#index.cgiecho "Content-type:text/html;charset=utf-8" echomysql= "Mysql-uroot-proot" sql= "show databases "$mysql-E" $sql "
The browser runs as follows:
In fact, from the above example, you will come to the conclusion that CGI is similar to PHP, except that PHP files use PHP syntax, the use of the CGI shell command, but can be run through the browser script, to obtain results.
Shell Script--Initial CGI