技术员联盟提供win764位系统下载,win10,win7,xp,装机纯净版,64位旗舰版,绿色软件,免费软件下载基地!

当前位置:主页 > 教程 > 服务器类 >

在Linux系统上部署Apache+Python+Django+MySQL环境

来源:技术员联盟┆发布时间:2018-01-29 06:03┆点击:

  Linux+apache+mysql+python+mod_python+Django

  说明:系统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,因为要动态加入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 已经配置好

  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

 

  效果如下:

20151224172409545.png (819×460)

  PS:关于mod_python

  mod_python是apache组织的一个项目,通过它,可以开发psp或cgi,mod_python功能强大,速度快,是非常优秀的web开发工具。

  Mod_python起源于一个被称为Httpdapy(1997)的项目。很长时间以来, Httpdapy并没有被称作mod_python,因为Httpdapy不是专门用于Apache的。 Httpdapy被设计成跨平台的,实际上最初是为Netscape server写的(那个时候被称为Nsapy)(1997)

  这个Httpdapy的README文件的摘要,很好的阐述了在HTTP server中嵌入Python所带来的挑战和解决方案。