Linux+apache+mysql+python+mod_python+django
Description: System Rhel 5.3, default installation httpd, MySQL, not installed, please download install rpm package, delete/etc/httpd/modules/mod_python.so, if any.
First, install Python
CD python-2.7.11
Installation
./config--prefix=/usr/local/python/make && make installln-s/usr/local/python/bin/python2.7/usr/bin/ln-s/ usr/local/python/bin/python/usr/bin/
Second, installation Setuptools
wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5= Fe1f997bc722265116870bc7919059eash Setuptools-0.6c11-py2.7.eggldconfig #让它生效
Third, install the MYSQLDB module
wget http://cdnetworks-kr-2.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/ Mysql-python-1.2.3.tar.gz tar zxvf mysql-python-1.2.3.tar.gzcd mysql-pythonpython2.7 setup.py build# #ln-S/usr/local/ python/bin/python2.7/usr/bin/(note establish connection) python2.7 setup.py Install # #安装
Test:
There is no hint that the description is correct.
Iv. installation of Mod_python
wget http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.0b.tgz
Install apr-devel-1.2.7-11.el5_5.2.i386.rpm, apr-util-devel-1.2.7-7.sel5_3.2.i386.rpm, HTTPD-DEVEL-2.4.EL5.CENTOS.I386.RPM, because you want to add the Python module dynamically, otherwise you can't find Apxs
Tar xvf mod_python-3.3.0b.tgzcd mod_python-3.3.0b./configure--with-apxs=/usr/sbin/apxs--with-python=/usr/local/ Python/bin/python # # # (Apache support Python) make && make install
Attention
LoadModule Python_module modules/mod_python.so This does not need to be added because the/etc/httpd/conf.d/python.conf has been configured well
7ervice httpd restart (reboot under Apache)
Test:
[Root@localhost conf]# python
Python 2.7.1 (r271:86832, Mar, 10:13:38) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on Linux2type "help", "copyright" , "credits" or "license" for more information.>>> import mod_python>>>
V. Installation of Django
wget Http://www.djangoproject.com/download/1.2.5/tarball/tar XFZ django-1.2.5.tar.gzcd django-1.2.5python2.7 setup.py Install
Test:
[Root@localhost conf]# python
Python 2.7.1 (r271:86832, Mar, 10:13:38) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on Linux2type "help", "copyright" , "credits" or "license" for more information.>>> import django>>>
Six, Test all
mkdr/wwwcd/www./usr/local/python/bin/django-admin.py startproject Mytestmytestpython manage.py runserver 0.0.0.0:8000
The effect is as follows:
PS: About Mod_python
Mod_python is a project of Apache organization, through which can develop PSP or Cgi,mod_python powerful, fast, is very excellent web development tools.
Mod_python originated from a project known as Httpdapy (1997). For a long time, Httpdapy has not been called Mod_python, because Httpdapy is not intended for Apache. Httpdapy is designed to be cross-platform, actually originally written for Netscape server (at that time called Nsapy) (1997)
The summary of this httpdapy Readme file is a good description of the challenges and solutions for embedding Python in HTTP server.
Apache processes requests in stages (e.g. read requests, parse headers, check access paths, etc.). These stages can be implemented as functions called "processors" (handler). Traditionally, the "processor" was written in C and compiled into Apache's module. Mod_python provides a way to extend Apache functionality by using a Python-written Apache processor. For an exhaustive description of the Apache request process, see Apache API Notes, or see mod_python-integrating python with Apache.
To easily migrate from CGI, a standard Mod_python processor provides a simulated CGI environment that allows the user to run legacy scripts under Mod_python without any modifications to the code (in most cases).
One of the main advantages of Mod_python is that it transcends traditional CGI in performance. The following is a very rough test. The test was done on a Pentium 1.2G machine running red Hat Linux 7.3. Ab is used to test 4 scripts, all from the standard CGI module input (since this is the way a typical Python CGI script starts), and then output a simple word "hello!". This result is based on 10,000 concurrent requests with 1.
Standard cgi:23 REQUESTS/S
Mod_python cgihandler:385 requests/s
Mod_python publisher:476 requests/s
Mod_python handler:1203 requests/s