Deploy the Apache + Python + Django + MySQL environment on Linux,
Linux + apache + mysql + python + mod_python + Django
Note: httpd and mysql are installed by default in rhel 5.3. If not, download and install the RPM package and delete/etc/httpd/modules/mod_python.so.
1. Install python
wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz tar xfz mod_python-2.7.11.tgz
cd python-2.7.11
Install
./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/
Ii. Install 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 # make it take effect
3. 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 to establish a connection) python2.7 setup. py install # install
Test:
[root@localhost conf]# python2.7
Python 2.7.1 (r271:86832, Mar 21 2011, 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 MySQLdb>>>
It is correct if no prompt is displayed.
4. Install 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 before installation, because you need to dynamically add python modules, otherwise you cannot 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 supports python) make & make install
Note:
LoadModule python_module modules/mod_python.so does not need to be added because it has been configured in/etc/httpd/conf. d/python. conf
7 ervice httpd restart (restart apache)
Test:
[root@localhost conf]# python
Python 2.7.1 (r271:86832, Mar 21 2011, 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>>>
5. Install 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 21 2011, 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>>>
6. 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 organized by apache. It can be used to develop psp or cgi. mod_python is a powerful and fast web development tool.
Mod_python originated from a project called Httpdapy (1997. For a long time, Httpdapy has not been called mod_python, because Httpdapy is not specifically used for Apache. Httpdapy was designed to be cross-platform. It was actually written for the Netscape server (called Nsapy at that time) (1997)
The abstract of the Httpdapy README file clearly describes the challenges and solutions for embedding Python in HTTP server.
Apache processes requests in stages (for example, read requests, parse headers, check access paths, and so on ). These stages can be called handler function implementations. Traditionally, the "processor" is a module written in C language and compiled into Apache. Mod_python provides an Apache processor written in Python to expand Apache functions. For a detailed description of the Apache request processing process, see Apache API Notes or Mod_python-Integrating Python with Apache.
To easily port data from CGI, a standard mod_python processor provides a simulated CGI environment that allows users to make no changes to the Code, run the legacy scripts in mod_python (in most cases ).
One of the major advantages of mod_python is that it outperforms traditional CGI in terms of performance. The following is a rough test. The test is completed on a Pentium 7.3 GB machine running Red Hat Linux. AB is used to test four types of scripts, all of which are input from the Standard cgi Module (because this is a typical Python cgi script), and then outputs a simple word "Hello! ". The result is based on 10000 concurrent requests.
Standard CGI: 23 requests/s
Mod_python cgihandler: 385 requests/s
Mod_python publisher: 476 requests/s
Mod_python handler: 1203 requests/s
Articles you may be interested in:
- Simple Apache + FastCGI + Django Configuration Guide
- Configure the django runtime environment in windows + apache + mod_python
- Deploy the Python Django project to the Apache server in Linux