I. install Apache with source code
In order to test the system, I downloaded the source code and compiled and installed an apache2.4. The installation process is simple. Note that parameters are added to configure.
Configuration:
./configure --prefix=$APACHE_HOME --enable-mods-shared=most --enable-ssl=shared --with-ssl=$SSL_HOME
(-- With-SSL is an SSL tool that can be enabled.) For detailed parameters, see Apache configuration parameters.
Compile and install:
makemake install
Then you can use bin/apachectl-K start and bin/apachectl-K stop to enable and disable Apache.
2. Note that apache2.4 must cancel the comment in CONF/httpd. conf to support CGI.
LoadModule cgid_module modules/mod_cgid.so
At the same time, the settings in the cgi-bin directory are as follows:
<Directory "/XXX/apache2/cgi-bin"> AllowOverride None Options +ExecCGI AddHandler cgi-script .cgi Require all granted</Directory>
After this configuration, you can call the CGI program. The following is a python CGI program. Open http: // localhost/cgi-bin/test. cgi in the browser to print the output statement.
#!/usr/bin/pythonprint "Content-type:text/html\r\n\r\n"print ''print ''print 'Hello Word - First CGI Program'print ''print ''
3. Install FastCGI Module 1. Download the FastCGI Module source code, https://github.com/byteinternet/libapache-mod-fastcgi. The latest version is 2.4.6. 2. decompress the FastCGI Module source code, get the directory mod_fastcgi-2.4.6, and enter the directory. 3. download the patch file of the FastCGI module for apache2.4: Release:
patch -p1 < byte-compile-against-apache24.diff
5. Rename makefile. AP2 in the directory to makefile to facilitate subsequent compilation. At the same time, modify the top_dir in the file to your Apache installation path. 6. Compile and install the SDK.
make&&make install
7. Add the statement for loading the module to $ apache_home/CONF/httpd. conf:
LoadModule fastcgi_module modules/mod_fastcgi.so
4. Apache allows you to configure the virtual host Apache allows you to use multiple ports of the same IP address to create different sites. The file that configures the VM is $ apache_home/CONF/extra/httpd-vhost.conf. My configuration is as follows. The listening port is 8888 and FastCGI is used to execute the CGI program.
Listen 8888<VirtualHost *:8888> ServerAdmin shishujuanhust@163.com DocumentRoot "$PATH" <IfModule alias_module> ScriptAlias /cgi-bin/ $PATH/cgi-bin/ </IfModule> <Directory /> AllowOverride none Require all granted </Directory> <Directory "$PATH/cgi-bin"> Options Indexes FollowSymLinks Options +ExecCGI AllowOverride None Order allow,deny Allow from 192.168 </Directory> AddHandler fastcgi-script .cgi ErrorLog "$PATH/logs/apache_error_log" CustomLog "$PATH/logs/apache_access_log" common</VirtualHost>
5. Run the fcgi program. After configuring the virtual host in section 4, you can run the fcgi program. Install a fcgi package at http://jonpy.sourceforge.net/fcgi.html. After installation, write the first fcgi program as follows according to the instructions in the document:
#! /Usr/bin/Python # This line must be added; otherwise, an error will occur. Import Jon. CGI as cgiimport Jon. fcgi as fcgiclass handler (CGI. handler): def process (self, req): req. set_header ("Content-Type", "text/plain") req. write ("Hello, world! \ N ") fcgi. Server ({fcgi. fcgi_responder: Handler}). Run ()
Then you can access it through the link. The parameter values in the link can be obtained through Req. Params. Get ('Param _ name.