部署环境:CentOS6,Apache-httpd-2.4,Python-3.8,Django-3.1
一、编译安装httpd-2.4:
# tar -zxvf httpd-2.4.17.tar.gz
# cd httpd-2.4.17
# ./configure --prefix=/usr/local/apache2.4 --with-included-apr --with-apr=/path/to/apr-httpd --with-apr-util=/path/to/apr-util-httpd/ --with-pcre=/path/to/pcre --with-ssl=/path/to/openssl --enable-so
# make && make install
二、编译安装Python3
# yum install libffi-devel //避免使用pip时出现ModuleNotFoundError: No module named '_ctypes'错误
# tar -xvJf Python-3.8.5.tar.xz
# cd Python-3.8.5
# ./configure --prefix=/usr/local/python3.8.5 CFLAGS=-fPIC //CFLAGS=-fPIC可避免后面编译mod_wsgi模块时出错
# vim Modules/Setup //修改Setup文件,以支持ssl
其中SSL=... 根据你实际情况填写。
# make && make install
# cd /usr/local
# ln -s python-3.8.5/ python3
# vim /etc/profile //将python3加入PATH路径 export PATH=$PATH:/usr/local/python3/bin
# python3 //检查python安装是否成功
三、编译安装mod_wsgi:
# tar -zxvf mod_wsgi-4.7.1.tar.gz
# cd mod_wsgi-4.7.1
# ./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/python3/bin/python3
# make
# make install
这时可以在apache的modules目录下找到mod_wsgi.so
四、配置apache+django:
假设django项目在/home/django-test/mysite目录下:
编辑httpd.conf文件,增加如下配置:
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / /home/django-test/mysite/mysite/wsgi.py
WSGIPythonHome /home/django-test/venv
WSGIPythonPath /home/django-test/mysite
<Directory /home/django-test/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>