CENTOS7.6(1810)+WDCP3+PYTHON3.7.5+DJANGO2.1.8环境搭建

直接上干货,按以下步骤完成APACHE使用WSGI完成DJANGO环境搭建

前言

环境版本

CENTOS:7.6.1810
PYTHON:3.7.5
DJANGO:2.1.8
APACEH:2.4.38
MYSQL:5.6.42
PHP:7.2.15

前置开发包安装

yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel ncurses-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel openssl-devel libffi-devel sqlite-devel

wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz
./config --prefix=/usr/local/openssl --openssldir=/usr/openssl shared zlib
make && make install

一、安装PYTHON3.7.5

1.1:wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
1.2:./configure --prefix=/usr/local/python3 --enable-shared --enable-optimizations
1.3:make && make install
1.4:ln -s /usr/local/python3/bin/python3 /usr/bin/python3
1.5:ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
1.6:cp /usr/local/python3/lib/libpython3.7m.so.1.0 /usr/lib64/
1.7:pip3 install --upgrade pip

安装时出现LookupError: unknown encoding: GB2312错误,需要./configure之前设置字符集,如下:

1.export LANG=zh_CH.UTF-8

2.export LANGUAGE=zh_CH.UTF-8

二、安装WDCP

2.1:wget http://dl.wdlinux.cn/files/lanmp_v3.3.tar.gz
2.2:sh lnmp.sh cus(依次选择1、2、2、6)

三、PYTHON虚拟环境

在WDCP创建的/www/web下创建安装虚拟环境的目录,也可以是其它目录,但不能在/root下,权限问题
3.1:python3 -m venv /www/web/venv-path
3.2:source /www/web/venv-path/bin/activate
3.3:pip3 install --upgrade pip
3.4:pip3 install django==2.1.8
退出虚拟环境命令:deactivate

四、安装wsgi模块:
文档地址:https://modwsgi.readthedocs.io/en/develop/user-guides/quick-installation-guide.html
4.1:wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.6.5.tar.gz
4.2:./configure --with-apxs=/www/wdlinux/httpd-2.4.38/bin/apxs --with-python=/usr/bin/python3
4.3:make && make install

五、修改APACHE配置,增加对mod_wsgi.so的引入,增加下面一行

LoadModule wsgi_module modules/mod_wsgi.so

六、WDCP创建站点,方法自行百度。

七、将DJANGO应用上到/www/web下的自建目录,如/www/web/dsite。
修改settings.py的ALLOWED_HOSTS = ['允许访问的域名']

八、修改新建站点的vhost.conf,增加如下配置:

参考文档:https://docs.djangoproject.com/zh-hans/2.2/howto/deployment/wsgi/modwsgi/

    Options FollowSymLinks
    AllowOverride All
    Require all granted

WSGIScriptAlias / /www/web/dsite/mysite/wsgi.py
WSGIPythonHome /www/web/venv-path
WSGIPythonPath /www/web/dsite


Require all granted

九、重启HTTPD服务

你可能感兴趣的:(python基础模块)