1.事先准备,安装apache2服务器和开发工具
apt-get install apache2
apt-get install apache2-dev python-dev #python2
apt-get install apache2-dev python3.5-dev #python3.5
2.编译mod_wsgi。
在https://github.com/GrahamDumpleton/mod_wsgi/releases下载mod_wsgi的源码
wget -c https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.21.tar.gz
tar zxfv 4.4.21.tar.gz
cd mod_wsgi-4.4.21/
./configure
make
make install
成功之后会提示mod_wsgi安装到了 /usr/lib/apache2/modules/mod_wsgi.so
3.apache的配置
(1) 启动mod_wsgi模块
echo "LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so" > /etc/apache2/mods-available/wsgi_module.load
a2enmod wsgi_module
(2) 添加网站配置
vim /etc/apache2/sites-available/python.conf
Alias /python “/var/www/python”
4.测试
vim /var/www/python/index.py
def application(environ, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b'This is a test page']
通过 http://{hostname}/python/index.py 访问。
Python程序员最常犯的十个错误:http://www.linuxdiyf.com/linux/16441.html
ubuntu14.04在Vim上配置Python开发环境:http://www.linuxdiyf.com/linux/15967.html
在Ubuntu下配置Python开发环境:http://www.linuxdiyf.com/linux/13748.html
Ubuntu下使用Eclipse和PyDev搭建完美Python开发环境:http://www.linuxdiyf.com/linux/6257.html
提高Python运行效率的六个窍门:http://www.linuxdiyf.com/linux/12569.html