I have only studied c language, but I have never studied prel. Many tutorials on the Internet are for prel, and few are for c. I spent an afternoon in Ubuntu, and finally wrote a helloworld cgi in c. This is the first step to get started with cgi. 1. install and configure apache server install apache2 server # sudoapt-getinstallapache2 configuration apache2 server configuration file in/etc/apache2/site
I have only studied c language, but I have never studied prel. Many tutorials on the Internet are for prel, and few are for c. I spent an afternoon in Ubuntu, and finally wrote a helloworld cgi in c. This is the first step to get started with cgi.
1. install and configure the apache server
Install the apache2 server
# Sudo apt-get install apache2
Configure the apache2 server
The configuration file is located at/etc/apache2/sites-enabled/000-default.
Open the configuration file with vi:
# Sudo vi/etc/apache2/sites-enabled/000-default
Modify the following two sentences:
DocumentRoot/var/www/html
ScriptAlias/cgi-bin // var/www/html/cgi-bin/
Pay attention to the space issue.
You can set these two directories by yourself, and the Set directories must actually exist. If they do not exist, mkdir will generate one.
DocumentRoot is followed by a directory containing HTML files.
ScriptAlias is followed by/cgi-bin/to/var/www/html/cgi-bin/, that is, the files in this directory are considered as cgi programs.
For example, if you access http: // 127.0.0.1/cgi-bin/hello. cgi in a browser, You can execute hello. cgi in cgi-bin.
Save the configuration.
Restart apache2:
# Sudo/etc/init. d/apache2 restart
2. Compile the hello. cgi program
Create a hello. c file under cgi-bin:
# Sudo vi hello. c
Write the following content:
# Include
Int main ()
{
Printf ("Content-Type: text/html \ n ");
Printf ("Hello, world \ n ");
Return 0;
}
Save and exit.
Compile:
# Sudo gcc hello. c-o hello. cgi
Run the command first.
# Sudo./hello. cgi
Check whether helloworld is output.
Then, you can type http: // 127.0.0.1/cgi-bin/hello. cgi in the browser.
The browser can display helloworld.
Iii. Permission issues
My method is brutal. I set the permissions of all related files and directories to 777.
# Sudo chmod 777 [file name or directory]
Here, we should first enter the door, and we will have time to study the permissions.