Linux+apache+mysql+python+mod_python+Django
說明:系統(tǒng)rhel 5.3,默認安裝httpd、mysql,沒有安裝的,請下載安裝RPM包,刪除/etc/httpd/modules/mod_python.so,如果有的話。
一、安裝python
?
1
2
wget
tar xfz mod_python-2.7.11.tgz <br>cd python-2.7.11<br>
安裝
?
1
2
3
4
./config --prefix=http://www.3lian.com/usr/local/python/
make && make install
ln -s /usr/local/python/bin/python2.7 /usr/bin/
ln -s /usr/local/python/bin/python/usr/bin/
二、安裝setuptools
?
1
2
3
4
5
wget #md5=fe1f997bc722265116870bc7919059ea
sh setuptools-0.6c11-py2.7.egg
ldconfig #讓它生效
三、安裝 mysqldb模塊
?
1
2
3
4
5
6
wget
tar zxvf MySQL-python-1.2.3.tar.gz
cd MySQL-python
python2.7 setup.py build
# #ln -s /usr/local/python/bin/python2.7 /usr/bin/(注意建立連接)
python2.7 setup.py install ##安裝
測試:
?
1
[root@localhost conf]# python2.7
?
1
2
3
4
5
Python 2.7.1 (r271:86832, Mar 21 2011, 10:13:38)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>
沒有提示說明是正確的。
四、安裝mod_python
?
1
wget
安裝前安裝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,因為要動態(tài)加入python模塊,要不然找不到apxs
?
1
2
3
4
tar xvf mod_python-3.3.0b.tgz
cd mod_python-3.3.0b
./configure --with-apxs=http://www.3lian.com/usr/sbin/apxs --with-python=http://www.3lian.com/usr/local/python/bin/python ###(apache支持python)
make && make install
注意
LoadModule python_module modules/mod_python.so這個不用添加,因為在/etc/httpd/conf.d/python.conf 已經(jīng)配置好
7ervice httpd restart (重啟下apache)
測試:
?
1
[root@localhost conf]# python
?
1
2
3
4
5
Python 2.7.1 (r271:86832, Mar 21 2011, 10:13:38)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mod_python
>>>
五、安裝Django
?
1
2
3
4
wget
tar xfz Django-1.2.5.tar.gz
cd Django-1.2.5
python2.7 setup.py install
測試:
?
1
[root@localhost conf]# python
?
1
2
3
4
5
Python 2.7.1 (r271:86832, Mar 21 2011, 10:13:38)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>>
六、測試全部
?
1
2
3
4
5
mkdr /www
cd /www
./usr/local/python/bin/django-admin.py startproject mytest
mytest
python manage.py runserver 0.0.0.0:8000
效果如下:
PS:關于mod_python
mod_python是apache組織的一個項目,通過它,可以開發(fā)psp或cgi,mod_python功能強大,速度快,是非常優(yōu)秀的web開發(fā)工具。
Mod_python起源于一個被稱為Httpdapy(1997)的項目。很長時間以來, Httpdapy并沒有被稱作mod_python,因為Httpdapy不是專門用于Apache的。 Httpdapy被設計成跨平臺的,實際上最初是為Netscape server寫的(那個時候被稱為Nsapy)(1997)
這個Httpdapy的README文件的摘要,很好的闡述了在HTTP server中嵌入Python所帶來的挑戰(zhàn)和解決方案。