CentOS 7 + Apache 2.4 + Flask 0.11 + Python 3.4 + Virtualenv配置过程

前端之家收集整理的这篇文章主要介绍了CentOS 7 + Apache 2.4 + Flask 0.11 + Python 3.4 + Virtualenv配置过程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1. 安装Python3

由于CentOS 7自带的是Python 2.7,而且一大批内置的应用比如yum等等都依赖于python2.7,因此无法将它直接卸载。使用

yum -y install epel-release
      or
yum -y install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
yum -y install python34 python34-pip
pip3 install virtualenv -i https://pypi.tuna.tsinghua.edu.cn/simple

可以安装Python3.4的环境,然后使用

$ python3

启动Python 3.4的环境。

2. 安装编译环境

CentOS 7使用yum默认安装的是Python 2.7的mod_wsgi,wsgi只能使用编译时指定的Python版本。如果想要使用Python3.5,就必须要重新编译mod_wsgi。首先安装编译环境:

yum -y groupinstall development
yum -y install zlib-devel openssl-devel sqlite-devel bzip2-devel python-devel openssl-devel libffi-devel openssl-perl libjpeg-turbo-devel zlib-devel giflib ncurses-devel gdbm-devel xz-devel tkinter readline-devel tk tk-devel
yum -y install httpd-devel python34-devel

然后删除系统自带的mod_wsgi

yum remove mod_wsgi

下载mod_wsgi的源代码包,解压缩后编译:

wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.5.9.tar.gz
tar zxvf ./4.5.9.tar.gz 
cd mod_wsgi-4.5.9
./configure --with-python=/usr/bin/python3;make;make install

3. 配置Apache

首先配置Apache加载mod_wsgi,键入以下命令:

cd /etc/httpd/conf.modules.d/
vi 10-wsgi.conf

输入:

LoadModule wsgi_module modules/mod_wsgi.so

修改一下Apache配置程序:

vi /etc/httpd/conf/httpd.conf

在最后增加以下的配置信息:

# VirtualHost configuration
#
# Load config files in the "/etc/httpd/conf.vhost.d" directory,if any.
IncludeOptional conf.vhost.d/*.conf

然后我们然后让Apache加载我的Flask应用程序:

cd /etc/httpd/conf.vhost.d/
vi 00-ipapp.conf

文件内容如下:

<VirtualHost *>
    ServerName 60.205.58.20

    WSGIDaemonProcess ipapp user=devel group=apache threads=5 python-home=/home/devel/ipapp/venv
    WSGIScriptAlias /ip /home/devel/ipapp/ip.wsgi

    <Directory /home/devel/ipapp>
        WSGIProcessGroup ipapp
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptReloading On
        Order deny,allow
        Require all granted
    </Directory>
</VirtualHost>

最后,使用systemctl restart httpd重启Apache搞定。

原文链接:https://www.f2er.com/centos/379396.html

猜你在找的CentOS相关文章