1。将 python 3.6.5 干净安装到 usr/local 和 usr/local/lib
我确保 YUM 是最新的:
$ yum update
编译器和相关工具:
$ yum groupinstall -y "development tools"
编译期间启用 Python 的所有功能所需的库:
$ yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-
devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
expat-devel
安装 Python 3.6.5:
$ wget http://python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
$ tar xf Python-3.6.5.tar.xz
$ cd Python-3.6.5
$ ./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath
/usr/local/lib"
$ make && make altinstall
2。使用 pip install 安装 mod_wsgi
使用刚刚安装的python3.6我运行了以下命令
$python3.6 -m pip install mod_wsgi
3。将 Mod_wsgi 加载到 apache 模块中
找到 apache 配置文件 /etc/apache2/conf/http.conf 并添加以下命令以通过指定安装路径来加载 mod_wsgi。
就我而言,将 loadModule 命令添加到 /etc/apache2/conf.d/includes/pre_main_global.conf
$ LoadModule wsgi_module /usr/local/lib/python3.6/site-
packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so
4。重启 Apache Server 并确认 mod_wsgi 已加载
$apachectl restart
$apachectl -M
查看列表并确保 mod_wsgi 是 apache 加载的模块的一部分。
5。配置虚拟主机并执行简单的 hello.py 测试
我的服务器已经托管了 7 个不同的站点。我只是创建了一个新的子域并将子域虚拟主机修改为看起来像
<VirtualHost mysite.com_ip:80>
ServerName wsgitest.mysite.com
ServerAlias www.wsgitest.mysite.com
DocumentRoot /home/account_username/public_html/wsgitest
ServerAdmin admin@mysite.com
<Directory /home/account_username/public_html/wsgitest>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /home/account_username/public_html/wsgitest/hello.py
ErrorLog /home/account_username/public_html/wsgitest/wsgitest_error.log
</VirtualHost>
修改虚拟主机后重启apache
根据本站创建一个hello.py wsgi应用-http://modwsgi.readthedocs.io/en/develop/user-guides/quick-configuration-guide.html
你好.py
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
所以我的 wsgitest 应用程序在服务器上看起来像这样
/home/account_username/public_html/wsgitest/hello.py
最后,像这样在浏览器上测试网站 - wsgtest.mysite.com
你应该会看到“Hello World”
我希望这对某人有所帮助