当前位置 主页 > 服务器问题 > Linux/apache问题 >

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

    栏目:Linux/apache问题 时间:2018-11-21 12:20

    这篇文章主要介绍了在Linux系统上部署Apache+Python+Django+MySQL环境的方法,使用到了mod_python与mysqldb模块进行连接,需要的朋友可以参考下

    Linux+apache+mysql+python+mod_python+Django
    说明:系统rhel 5.3,默认安装httpd、mysql,没有安装的,请下载安装RPM包,删除/etc/httpd/modules/mod_python.so,如果有的话。
    一、安装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

    安装

    ./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/

    二、安装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 #让它生效

    三、安装 mysqldb模块

    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/(注意建立连接)python2.7 setup.py install ##安装

    测试:

    [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>>> 

    没有提示说明是正确的。

    四、安装mod_python

    wget http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.0b.tgz

     安装前安装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

     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支持python)make && make install

    注意
      LoadModule python_module modules/mod_python.so这个不用添加,因为在/etc/httpd/conf.d/python.conf 已经配置好
    7ervice httpd restart (重启下apache)
    测试:

    [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>>>

    五、安装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

    测试:

    [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>>>