This article assumes that you have installed Linux (the Linux version of this article is Fedora Core3) and has root permissions.
1, install Apache
First download the latest version of Apache HTTP server to Apache's home page, address http://httpd.apache.org/
This article is written in 2006.4.29,apache version for 2.2.0. If you want to use this version, please click: http://mirror.vmmatrix.net/apache/httpd/httpd-2.2.0.tar.gz
Install Apache:
Switch to the httpd-2.2.0.tar.gz directory, and then:
# tar Xvzf httpd-2.2.0.tar.gz
At this point there is a folder httpd-2.2.0 in the directory, switch to the folder:
# CD./httpd-2.2.0
I don't know which folder you want to install Apache to, and we assume we want to install it under/usr/local/apache2/.
Enter the following command:
#./configure--prefix=/usr/local/apache2
# make
# make Install
After executing these 3 commands, Apache is installed in your/usr/local/apache2 directory.
Switch to the directory and see what you can do.
# CD./usr/local/apache2
# ls
You can see that there are/bin,/conf,/htdocs,/cgi-bin, and so on. Apache has not yet started, we start with the tool/bin in the Apachectl directory, first switch to the/bin directory:
# CD./bin
And then start:
#./apachectl Start
At this time, enter http://localhost/in the address bar to see if there is a successful message? (I see "it works!") The information, of course, different versions will be different, depending on the content of the index.html under your/htdocs.
Replace the/usr/local/apache2/htdocs/index.html with your paging file.
Here, we assume that your Apache server has been installed successfully. If you have any questions, please search the Internet or contact me:
Lonestep at Gmail D. T com
2, configure Apache to execute the CGI program
By default, the CGI program must be placed in the Cgi-bin directory, we first configure the CGI program under Cgi-bin to be properly executed,
The following will show you how to get Apache to execute a CGI program that is placed in a different directory.
1, on, we have to install Apache into the/usr/local/apache2 directory, switch to the/usr/local/apache2/conf directory, which has a httpd.conf file, edit this file:
# cd/usr/local/apache2/conf
# VI httpd.conf (assuming your text editor is VI, if you use another editor such as Emacs, Gedit, Kedit, and so on, replace VI with their command)
Find one line like this:
# scriptalias/cgi-bin/"/usr/local/apache2/cgi-bin/"
Remove the ' # ' in front of this line and restart Apache:
# CD./bin (or Cd/usr/local/apache2/bin)
#./apachectl Restart
OK, if you put a CGI program ' test.cgi ' to Cgi-bin, in the address bar
Enter http://localhost/cgi-bin/test.cgi to see if it can be executed.
If not, please email me:
2, if you want to change the execution of the CGI directory (without the default Cgi-bin directory), then the change just
scriptalias/cgi-bin/"/usr/local/apache2/cgi-bin/" is:
scriptalias/someotherdirectory/"/usr/local/apache2/cgi-bin/"
Then restart Apache.
The above process is relatively simple, if you encounter a problem not covered in this article, or with this article assumes that different conditions,
Please go to the Internet to find a solution, if not yet (once and once again) can email me:
A. CGI configuration process
1.CGI to execute directory settings. Typically in the/usr/local/apache/cgi-bin/folder. Relevant information can be found in the httpd.conf configuration file. For example, I put the CGI program is test.pl so that the HTTP please address is: http://localhost/cgi-bin/test.pl
The execution directory for 2.CGI is generally read only for all security considerations. The configuration in the corresponding httpd.conf executable CGI is as follows:
<Directory/usr/local/apache/htdocs/somedir>
Options +execcgi
</Directory>
3.htaccess file
A. htaccess file is a method that configures the basis of a set of instructions for each directory. When the Apache service is a resource, it looks like the file required by the file it provides in the directory. htaccess, if it thinks there is, it will apply to instructions found in the htaccess file that can be allowed allowoverride instructions, which specifies which types of instructions can appear in these files, or, if they are not allowed. Allow instructions that we will need for this purpose, the following configuration will need to be configured on your home server.
Two, the contents of the configuration file and parameter meaning
There are three files in the configuration directory, respectively:
1. Conf/httpd.conf:
ServerType: There are two values to choose from standalone and inetd
Standalone: Indicates that your httpd process is listening in the background as a separate daemon (daemon) for requests from clients.
INETD: means that your httpd process is not running as a daemon (daemon), but is being listened to by Inetd the process of this Internet service, and once a client requests it, he automatically launches httpd this process to provide the appropriate services The default is standalone way, if you are not to ARPA Berkeley Services are not very understanding, do not change.
Port: The port number that you assign to your Web SERVER.
The default port for HTTPD is 80, or it can be assigned to a web SERVER that is greater than 1024.
The port number. If you do this, you must keep up with your port number after your URL to access your
The page. For example, the port number you assign to your service is 8888, then you need to enter
http://domainname:8888
ServerAdmin: The email address of the service administrator, the default is the root user of this machine, so it is
Root@localhost
ServerRoot: Directory used to store configuration, error, and record files for a service.
Bindaddress: The IP address of the virtual host. With a machine virtual multiple machines.
ErrorLog: A file used to store error messages for your Web server.
Transferlog: A record file that is used to store file names that are transmitted.
Pidfile: The specified file holds the process number of the httpd process to stop the Web SERVER.
Scoreboardfile: Information that is used to store processes.
ServerName: The name of your machine, if you have a domain name, fill in your local domain name. If not, then
Fill in your Host name or IP address.
Timeout: Delay of transmission or reception. Greater than this time server will disconnect this link.
KeepAlive: (on or off) allows a link to send multiple requests at the same time.
KeepAliveTimeout: (default is 15) the time to wait for the next request.
MaxClients: (default is 150) the maximum number of clients allowed.
Usually the default values for the above parameters are not changed, but you should be aware if you are running several Web servers on a single machine at the same time. First, you have to assign a different port number to each Web SERVER. Second, specify their errorlog files and pidfile files separately. Third, do not understand the parameters do not arbitrarily change, even if the changes will be changed one at a time, and leave a record in order to recover.
2./conf/access.conf:
The main is the function of the directory and access control settings. The following is a description of the default page configuration file. The location of the file is:/etc/httpd/conf/access.conf.
The first part of the document is not annotated as follows:
<Directory/home>
Options Indexes includesnoexec
AllowOverride None
</Directory>
It is noted that this section begins with the <Directory/home> and ends with </Directory>. The beginning of the section <Directory/home> indicates that the following setting is for the/home directory. Options This command has many parameters, the functions of which are as follows:
All of the options except the MultiViews feature.
ExecCGI opens the function of executing a CGI program.
FollowSymLinks to open a dynamic link, when a customer access to the directory will automatically
Link to another related directory.
Includes to open the service-side reference function.
IncludesNOEXEC opens the service-side reference function, but the #exec and CGI program references will
Be forbidden.
Indexes If there is no index.html file in the directory, a list of files is displayed.
SymLinksIfOwnerMatch only if the target file or directory of the link is the same as the current directory
When the user opens the link.
Next is the allowoverride parameter, which is set to access control. This sets him to none, indicating that the feature is not turned on.
The second part is:
<Directory/home/httpd/html>
Options Indexes Includes execcgi followsymlink
AllowOverride None
Order Allow,deny
Allow from all
</Directory>
The third part is:
<Directory/home/httpd/cgi-bin>
AllowOverride None
Options execcgi
</Directory>
Indicates no access control for/home/httpd/cgi-bin and allows CGI programs to be executed. That means it's a directory for CGI programs.
3./conf/srm.conf
It is mainly used to specify the location of your document.
The first parameter is: DocumentRoot. Used to specify the address of the main document.
The second parameter is: Userdir. Used to specify the location of the personal home page. If you have a user's home directory for/home/jon when entering the Http://yourdomain/~jon system in the URL will go to/home/jon/x/to fetch the user's personal homepage. where x is the directory specified by Userdir.
The third parameter is: DirectoryIndex. The name of the index file used to declare the lookup.
Others do not change and do not defend. A few of the above options are usually used.
Specific Examples
You need to establish a boot-initiated Web server. Assume that your document directory is/home/jon/html.
First, change the contents of the/etc/httpd/conf/access.conf file. Change the original document's directory to the new document directory.
For example, the following changes:
Copy Code code as follows:
<Directory/home/httpd/html>? <Directory/home/jon/html>
Options Indexes Includes execcgi followsymlink
AllowOverride None
Order Allow,deny
Allow from all
</Directory>
<Directory/home/httpd/cgi-bin>? <Directory/home/jon/cgi-bin>
AllowOverride None
Options execcgi
</Directory>
As the corresponding changes are made, note that/home/jon/cgi-bin is the directory for your CGI program.
Next, modify the/etc/httpd/conf/srm.conf file.
Change documentroot/home/httpd/html to Documentroot/home/jon/html
Finally, modify the/etc/httpd/conf/httpd.conf file.
Replace the original content that follows the ServerName parameter with your native IP address or host name, and remove the previous annotation character "#". The configuration here is:
ServerName Jon (Jon is my host name)
To start the httpd process anew:
#/etc/rc.d/init.d/httpd restart
four. Preparation of CGI programs
First of all, all output from your CGI program must be preceded by a MIME type title
1. First of all to determine content-type:text/html