Installing Apache Server
Apache server:https://archive.apache.org/dist/httpd/
Steps:
1. Download and unzip the file to the C:\Apache24 path.
2. Open the command line, CD to C:\Apache24\bin directory, execute httpd.exe-k install command to mount Apache service
3. Open the Conf/httpd.conf file to modify the configuration
Listening on port 8080
Configure the Administrator mailbox
Configure domain Names
4. Execute the httpd instruction in the Command Line window to start the server
In the browser access: localhost:8080, if the display it works! indicates that the installation was successful.
If the port is occupied, use the Netstat-ano command to view the PID of the process that occupies the port and end the process, or modify the configuration of the listening port.
If the MSI installation file is installed directly, open the Bin/apachemonitor.exe.
Related Catalogue Description:
1.bin: Execute file directory
2.cgi-bin:cgi file Directory
3.CONF: Configuration
4.error: Error
5.htdocs: Site root directory
6.icons: Icon
7.logs: Log
8.manual: Manual
9.modules: module (Dynamic Library) file directory
Configuring the Enable CGI feature
Open the httpd.conf file in the Conf directory
1. Dismiss comments for CGI programs
2. Add CGI settings: Options Indexes execcgi
Hello CGI
Development environment Description: Win7, VS2012
1. Write the code for C + + programs
#include <stdio.h>void main () {printf ("context-type:text/html; \ n ");p rintf (" <! DOCTYPE HTML public \ "-//IETF//DTD HTML 2.0//en\ >");p rintf ("
2. Compile the source code, copy the generated EXE file to the Cgi-bin directory, and modify the suffix named. CGI.3. Accessing CGI files in the browser
http://localhost:8080/cgi-bin/hello.cgi
Attention:
1. The content of the output will be displayed as the source code of the webpage, so the output content should conform to the HTML standard.
2. On the console output "\ n" does not appear on the page is a newline, you can output "<br/>" to achieve line break.
3. You can view the relevant log information in the logs directory.
Error:
1.Premature End of script headers:hello.cgi
hello.cgi the content of the output prematurely ends the script header. Check that the output is in accordance with the HTML standard.
Enable remote control of the computer
1. In the Htdocs directory, add a cmd.html file to submit the command, the source code is as follows:
<form method= "POST" action= "http://localhost:8080/cgi-bin/cmd.cgi" ><input type= "text" size= "+" name= "cmd" Value= "tasklist"/><input type= "Submit" name= "Submit" value= "Execute"/></form>
2.C Program Source CodeIdeas
(1). Gets the parameters that are submitted from the form in the HTML and replaces some of the strings, such as the + need to change to a space,%2f replace with/.
(2). Executes the relevant command and outputs the result in the file object in memory.
(3). Display the results of the execution to the Web page.
The source code used in the strlib.h here >> "C Language string library encapsulation"
3. Compile the exe executable file, copy the exe file to the Cgi-bin directory, and modify the suffix name to CGI. such as: Cmd.exe--and cmd.cgi.
4. Access the http://localhost:8080/cmd.html in the browser and submit the command.
Execution results
CGI programming for "C + +"