centos搭建Apache+mod_wsgi+Django环境

  • 软件版本

    httpd(2.2),httpd-devel,python(2.7.14),django(1.10.8),setuptools-0.6c11,mod_wsgi-3.4

  • 安装步骤:

    1.安装httpd(yum方式)

     #httpd-devel是为了apxs,如果不安装httpd_devel安装mod_wsgi会不成功
     yum install httpd httpd-devel 

    2.安装python(源码方式)

    
    # 源码目录在/usr/soft
    
    
    # 解压后的python在/usr/soft/Python-2.7.14
    
    cd Python-2.7.14
    
    #需要制定--enable-shared
    
    ./configure --prefix=/usr/local/python --enable-shared

    第一次安装时出现了如下错误:python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or。

    解决方式为(参考网上资料):
    在/etc/ld.so.conf.d目录下创建python2.7.conf文件,并写入/usr/local/python
    然后执行/sbin/ldconfig -V命令
    这个问题是因为安装python时使用–enable-shared引起的.
    (在第一次安装python的时候出现了这个问题,我把python卸载后重新安装的时候就没有出现上面这个问题。)

    3.安装mod_wsgi.so

    其实就一个模块,但是费很大劲才安装成功.

     #源码路径在/usr/soft/mod_wsgi-3.4
     ./configure
     make && make install

    第一次在安装的时候按照网上的讲法使用了./configure –with-python=/usr/local/python
    但是安装不成功,第二次没有使用–with-python时安装成功了

    4.安装Django

    这个安装比较容易,前提是先安装setuptools

    4.1 安装setuptools

    
    #源码路径在/usr/soft/setuptools-0.6c11
    
     python setup.py build
     python setup.py install

    4.2 安装Django

    
    #源码路径在/usr/soft/Django-1.10.8
    
    python setup.py install
  • httpd部署Django
# httpd.conf
# 加载mod_wsgi.so扩展
LoadModule wsgi_module modules/mod_wsgi.so

#指定项目的wsgi.py配置文件路径 
WSGIScriptAlias / /var/www/html/mysite/mysite/wsgi.py
#指定项目路径 
WSGIPythonPath /var/www/html/mysite

<Directory /var/www/html/mysite>
   <Files wsgi.py>
     Order deny,allow
     Allow from all
   </Files>
</Directory>

配置过程中遇到的问题:

mod_wsgi (pid=38804): Target WSGI script ‘/var/www/html/mysite/mysite/wsgi.py’ cannot be loaded as Python module.
[Fri Dec 29 23:31:32 2017] [error] [client 192.168.75.6] mod_wsgi (pid=38804): Exception occurred processing WSGI script ‘/var/www/html/mysite/mysite/wsgi.py’.
[Fri Dec 29 23:31:32 2017] [error] [client 192.168.75.6] Traceback (most recent call last):

[Fri Dec 29 23:31:32 2017] [error] [client 192.168.75.6] import datetime
[Fri Dec 29 23:31:32 2017] [error] [client 192.168.75.6] ImportError: /usr/local/python/lib/python2.7/lib-dynload/datetime.so: failed to map segment from shared object: Permission denied

解决方法:
关闭系统的selinux

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值