Host environment: RedHat9 Cross Compiler: arm-linux-gccversion4.3.2 platform: s3c2440 (a) compiled boa from Boa's official website http: www.boa.org downloaded its release version source code, version 0.94.13. First extract the source code, call out the Super Terminal and execute: #tarxzfboa-0.94.13.tar.gz # cdboa-0.9 host environment: R EdHat9
Cross Compiler: Rm-Linux-gcc version 4.3.2
Platform: s3c2440
(1) Compile boa
Download its release source code from the http://www.boa.org/on Boa's official website, with version 0.94.13. First put the source code ExtractTo call up the Super Terminal and execute:
# Tar xzf boa-0.94.13.tar.gz
# CdBoa-0.94.13/src
Generate MakeFile
#./Configure
Modify Make FileFile, find CC = gcc, change it to CC = arm-linux-gcc, find CPP = gcc-E, and change it to CPP = arm-linux-gcc-E, save and exit.
Then run make to compile. the following error occurs:
"Util. c: 100: 1: pasting" t "and"-> "does not give val IdPreprocessing token make "error prompt,
Modify the compat. h file:
# Define TIMEZONE_OFFSET (foo) foo #-> tm_gmtoff
Changed:
# Define TIMEZONE_OFFSET (foo) foo-> tm_gmtoff
Compiled successfully.
In addition, you also need to modify a src/log. c
Comment out
If ( DuP2 (error_log, STDERR_FILENO) =-1 ){
DIE (\ "unable to dup2 the error log \");
}
Is:
/* If (dup2 (error_log, STDERR_FILENO) =-1 ){
DIE (\ "unable to dup2 the error log \");
}*/
Otherwise, an error occurs:
Log. c: 73 unable to dup2 the error log: bad file deor
Finally, the s of the Cross-compiler is optimized. TrIp CommandThe debugging information is stripped, and the final program size is only about 60 kb.
# Make
# Arm-linux-strip boa
(2) Configure boa
After the Boa software is installed, You need to configure Boa. The configuration file is boa. conf, which is in the source code. Copy it to the/etc/boa directory of the embedded Linux root file system. Then, modify the important parts of this file as follows [2].
# [3] The listening port number, which defaults to 80 and is not modified
Port 80
# Comment out the called IP address. This indicates that the IP address is bound to INADDR_ANY and is assigned to all the IP addresses of the server. Do not set static fixed server addresses.
# Listen 192.68.0.5
# Set which user of the Linux User Group has the Boa permission
User root
Group root
# Error log file. The design path is in/dev/console.
ErrorLog/dev/console
# Access log files. If it is set to/dev/null, The AccessLog function is disabled. When the server is started, log files are not loaded.
AccessLog/dev/null
# Server name
ServerName friendly-arm
# The main directory of the HTML document. The accessed page is placed in this directory.
DocumentRoot/www
# Default index file name of the HTML directory.
DirectoryInd ExIndex.html
# Maximum number of HTTP sustained requests allowed by a connection.
KeepAliveMax 1000
# The number of times the server waits for two requests during HTTP persistence, in seconds.
KeepAliveTimeout 10
# Specify the mime. types [4] file location.
MimeTypes/etc/mime. types
# The default MIME type used when there is no or unknown file extension.
DefaultType text/plain
# Provide the PATH environment variable value of the CGI program.
CGIPath/bin:/usr/sbin:/sbin
# Specify the actual path corresponding to the virtual path of the CGI script./www/cgi-bin/is the directory of my root file system.
ScriptAlias/cgi-bin // www/cgi-bin/
Copy the host/etc/mime. types file to the etc directory of the root file system.
(3) test and error handling
1. Static web page Testing
Place a static webpage under the main directory/WWW of the HTML document. In order to facilitate the modification of the file name to index.html, and enter the target board ip address in the browser, such as http: // 192.168.1.200, a static webpage will appear.
2. cgi Test
First, write the Helloworld. c program
Int main (void)
{
Printf (\ "Content-type: text/htm LnN \ "); // This sentence must be added
Printf (\ "Hello, world .\");
Exit (0 );
}
Cross-compile arm-linux-gcc-o helloworld. cgi helloworld. c
Set helloworld. copy cgi to the/www/cgi-bin/directory, pay attention to the execution permission, and enter http: // 192.168.1.200/cgi-bin/helloworld in the browser. cgi to see the corresponding web page.
(4) cgi programming
There are many ways to design dynamic web pages. CGI is one of them. The Boa Server supports cgi. Two methods are described to use cgi to communicate with the server.
First, understand the basic concept of cgi. CGI is a Common Gateway Interface, an Interface for communication between local and remote applications on the HTTP server, the program must run on the network server. Physically, CGI is a program that runs on the Server and provides the same Html page interface as the client. This is probably hard to understand. Let's look at a practical example: most of my personal pages now have a message book. The work of the message book is as follows: the user first enters some information, such as the name, on the client. Next, the user clicks "Leave a message" (currently working on the client), and the browser sends the information to a specific CGI program in the cgi directory of the server, as a result, cgi programs are processed on the server according to the predefined method. In this example, the information submitted by the user is stored in the specified file. Then the cgi program sends a message to the client, indicating that the request task has been completed. At this time, the user will see the "End of message" in the browser. The whole process is over.
The main process of n CGI is:
1. A user requests to activate a CGI application;
2. the CGI application extracts user input information from the interactive homepage;
3. transmit user input information to server host applications (such as database queries 〕;
4. Return the server processing result to the user through an HTML file;
5. The CGI process ends.
N HTML language and HTML form
HTML (Hypertext Markup Language) is a simple markup language used to create platform-independent hypertext documents, it can be used to mark hypertext messages, emails, documents, supermedia, menu options, database query results, and simple structured documents with embedded images. HTML is the document encoding, including the text to be displayed, how the text is formatted, the name of the image to be displayed (not the image itself), and other important information. When you connect to a webpage, the Web browser (such as IE) "constructs" the webpage according to the HTML structure in the memory, and then displays the assembled webpage on the screen.
Generally, a browser can only use HTML requests to obtain static Web pages from the server for browsing. If you need to submit some data to the server through the browser for processing and return results for interaction, HTML forms are used. HTML forms are the main input methods for users to submit data through a browser. They are composed of common text, tags, and some special elements called "controls" (such as check boxes, radio buttons, menus, etc) and controls. The user enters data by entering or selecting the control content, and finally submits the data to the server for processing.
The following is an example of a form:
Some FORM parameters are described as follows:
1. action specifies the CGI script to be called
2. methed defines the method for submitting a form. There are two methed types: GET and POST. GET is the default CGI transmission method. The data entered by the user is attached to the URL and sent to the Web server. When the POST method transmits data, the CGI processing program on the server side receives the transmitted data from the SID.
3. re SetAppearance and SuBmit is similar, but once you press it, all input values in this form will be cleared, or return to the initial value.
Working Mechanism of n CGI
In the previous section, HTML forms are required for the browser to submit data. Then, how does the server identify and process the data? CGI is used to facilitate information interaction between browsers and WEB servers.
The interface specification between the CGI (common gateway interface) WEB server and the external program running on the server side. According to this specification, the external program compiled and run is called the CGI program, the purpose is to achieve dynamic interaction between the Web server and the client browser. The CGI program is called by the Web server to implement interaction with the WEB browser. As shown in, the Web server sends the information sent by the WEB browser to the CGI program for processing, after processing, the CGI program sends the response result back to the Web server, and then the Web server sends it to the Web browser. To call other external applications, such as database services, the CGl program interacts with external applications.
The interaction process between the browser and the Web server is as follows:
(1) The client uses the TCP/IP protocol to establish a connection with the server and send a URL request;
(2) The Web server calls the CGI program to the corresponding directory and uses the parameters passed by the client as the parameters of the CGI program. The CGI program calls the corresponding external program to complete the operation;
(3) The CGI program returns the processing result to the HTTP server in a recognizable format;
(4) The Web server returns the data to the client for processing and displays the CGI execution result.
The CGI program communicates with the Web server and transmits relevant parameters and processing results through command line parameters, standard output, and environment variables. As shown in, the standard input (STDIN) of CGI is the standard output (STDOUT) of the server, while the standard output of CGI is the standard input of the server. The customer's request information is transmitted through the standard output of the server to draw the standard input of CGI. After CGI processes the information, it sends the result to its standard output, that is, the standard input of the server, the server then sends the processing result to the client. Taking boa as an example, the entire communication flow chart is as follows:
At the same time, CGI programs can use environment variables to obtain user data transmitted by Web servers. Common environment variables include:
1. SERVER-NAME: The machine NAME or IP address in the CGI sequence.
2. SERVER-INTERFACE: Type of the www server, for example, CERN or NCSA.
3. SERVER-PROTOCOL: communication PROTOCOL, which must be HTTP/1.0.
4. SERVER-PORT: tcp port. Generally, the web PORT is 80.
5. HTTP-ACCEPT: the type of data that the HTTP-defined browser can accept.
6. HTTP-REFERER: the URL of the file that sends the form. (Not all browsers send this variable)
7. HTTP-USER-AGENT: information about the browser that sends the form.
8. GETWAY-INTERFACE: CGI program version, in unix cgi/1.1.
9. PATH-TRANSLATED: actual PATH name included in PATH-INFO.
10. PATH-INFO: the additional PATH used by the browser to send data in GET mode.
11. SCRIPT-NAME: The Path NAME of the CGI program.
12. QUERY-STRING: the data entered in the form, the content after the URL intermediate number.
13. REMOTE-HOST: the sender's HOST name, which cannot be determined.
14. REMOTE-ADDR: the IP address of the machine that sends the program.
15. REMOTE-USER: the name of the sender.
1) use shell scripts to obtain the QUERY_STRING environment variable
This method is usually applicable to forms submitted using the get method. forms submitted using the post method must be obtained through standard output. However, the boa Server has the same effect in the two methods. Even if the post method is used, the corresponding information can still be obtained in the url. The typical shell program is as follows (friendly led test script, at/www/leds. cgi ):
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service