Build apache+fastcgi environment on Linux, say more is tears AH. I spent a few days, open source software, although easy to use, but the version of a large number of documents, nothing can only be explored. Finally successfully run, hereby record.
One. Apache Installation
Download apache-2.2.27 version here, general configure make command, easy to install
wget HTTP://MIRRORS.CNNIC.CN/APACHE//HTTPD/HTTPD-2.2.27.TAR.BZ2TAR-XJZF HTTPD-2.2.27.TAR.BZ2CD httpd-2.2.27./ Configure--prefix=/usr/local/apache2make && make install
Two. Apache Configuration
<directory "/usr/local/apache2/cgi-bin" >allowoverride noneoptions Indexes execcgi # Execute Cgiorder allow,denyAllow From All</directory> #添加文件映射AddHandler cgi-script. CGI. py
Running the service:./apachectl start
Open http://localhost, success will show It works!
Three. Compile and install the FastCGI module
FastCGI has a number of branch versions, MOD_FASTCGI official address: http://www.fastcgi.com/, this is the official extension module, has been a long time without maintenance; And the download link is dead.
Mod_fcgid is an official Apache-maintained version, compatible with mod_fastcgi binary, the original FASTCGI program can work without recompiling. It has done a lot of mod_fastcgi on the basis of the
Choose mod_fastcgi Test here, the production environment is not recommended to use:
wget HTTP://WWW.FASTCGI.COM/DIST/MOD_FASTCGI-2.4.6.TAR.GZTAR-XZVF MOD_FASTCGI-2.4.6.TAR.GZCD MOD_FASTCGI-2.4.6CP MAKEFILE.AP2 makefilemake top_dir=/usr/local/apache2make Top_dir=/usr/local/apache Install
Edit httpd.conf after compiling, add fastcgi module
LoadModule Fastcgi_module modules/mod_fastcgi.so
Four. Test run
Download Install jnopy, fastcgi python module
CD jonpy-2.2.27
Python setup.py Install
#!/usr/bin/pythonimport jon.cgi as Cgiimport jon.fcgi as Fcgiclass Handler (CGI. Handler):d EF process (self, req): Req.set_header ("Content-type", "Text/plain") req.write ("Hello, world!\n") fcgi. Server ({fcgi. Fcgi_responder:handler}). Run ()
Run 500 error again, view log: [ERROR] No such file or directory exec of '/usr/local/apach2/cg-bin/hello_fcgi.py ' failed
This is strange, clearly in the/cgi-bin directory, print the path is normal, how can not find it? Is this script has a fishy, manually run to see, error:./hello_fcgi.py:/usr/bin/python^m:bad Interpreter: No file or directory
Originally this file has special characters, files copied from Windows is easy to appear this problem, VI open file, Direct: Set Ff=unix Save exit can
Five. Installing the FASTCGI Development Library
If the sequence of steps above indicates that the environment is already set up, C + + programs are deployed below
5.1 Installing the FASTCGI Development Library
wget http://www.fastcgi.com/dist/fcgi.tar.gzcd Fcgi-2.4.1./configuremakemake Install
Make error, error: ' EOF ' is not declared in this scope, which EOF is not stdio.h, add code in Libfcgi/fcgio.cpp #include <stdi O.h>, make again, everything's fine.
5.2 Coding Test
#include "fcgi_stdio.h" #include <stdlib.h>void main (void) {int count = 0;while (fcgi_accept () >= 0) printf (" content-type:text/html\r\n "\ r \ n" "<title>fastcgi hello!</title>" "Compilation: Gcc-o fcgi_test.fcgi cgi_test.c-i/usr/local/include-l/usr/local/lib-lfcgi
Size: 13.6 KB size: 15.8
Linux +apache+fastcgi running C + +