软件版本
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