1. Traditional CGI:
Vim/var/www/cgi-bin/hello. py
#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
Print "Content-type: text/html \ n"
Print "Hello World"
Chmod a + x hello. py
Vim/etc/httpd/conf/httpd. conf
ScriptAlias/cgi-bin // var/www/cgi-bin/
2, Mod_Python (http://www.modpython.org /)
Wget http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.1.tgz
./Configure -- with-apxs =/data/apache2221/bin/apxs -- with-python =/usr/bin/python
Make
Make install
Vim/etc/httpd/conf. d/python. conf
LoadModule python_module modules/mod_python.so
<Directory/var/www/mod-python>
AddHandler mod_python. py
# Mod_python.publisher
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
Vim/var/www/mod-python/mod_python_publisher.py
#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
From mod_python import apache
Def index (req ):
Req. log_error ('handler ')
Req. content_type = 'text/html'
Req. send_http_header ()
Req. write ('Req. write ('Hello World! -Mod_python.publisher ')
Req. write ('</body> <Directory/var/www/mod-python>
AddHandler mod_python. py
# Custom handler
PythonHandler mod_python_handler
PythonDebug On
</Directory>
Vim/var/www/mod-python/mod_python_handler.py
#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
From mod_python import apache
Def handler (req ):
Req. log_error ('handler ')
Req. content_type = 'text/html'
Req. send_http_header ()
Req. write ('Req. write ('Hello World! -Custom handler ')
Req. write ('</body> Return apache. OK
3, Mod_wsgi (http://code.google.com/p/modwsgi)
Wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
./Configure -- with-apxs =/data/apache2221/bin/apxs -- with-python =/usr/bin/python
Make
Make install
Vim/data/apache2221/conf/httpd. conf
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias/wsgi // var/www/wsgi/
<Directory "/var/www/wsgi">
Order allow, deny
Allow from all
</Directory>
Vim/var/www/wsgi/hello. py
#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
Def application (environ, start_response ):
Status = '100 OK'
Content_type = 'text/html'
Output = ['Hello world']
Response_headers = [('content-type', content_type)]
Start_response (status, response_headers)
Return output