ubuntu 13.04 安装 apache2.2+mod_wsgi+Django

来源:互联网 发布:java 并发 面试 编辑:程序博客网 时间:2024/04/30 09:08

超简单系列:ubuntu 13.04 安装 apache2.2+mod_wsgi+Django

超简单系列开发环境部署均用ubuntu系统内置安装包,技术有限未使用源代码编译最新版程式。

1,Ubuntu更新系统

sudo apt-get updatesudo apt-get upgrade

2,安装apache,mod_wsgi,Django

sudo apt-get install apache2 libapache2-mod-wsgi  python-django

更多Ubuntu系统内置安装包请搜索:Ubuntu Packages Search

3,配置Django环境

sudo mkdir  /opt/wwwrootcd /opt/wwwrootsudo django-admin startproject hello

    创建wsgi文件

sudo mkdir /opt/wwwroot/hello/apachesudo gedit /opt/wwwroot/hello/apache/django.wsgi

    文件django.wsgi贴入下面内容

django.wsgi内容
import osimport syssys.path.append('/opt/wwwroot')sys.path.append('/opt/wwwroot/hello')path = '/opt/wwwroot'if path not in sys.path:    sys.path.insert(0, '/opt/wwwroot')os.environ['DJANGO_SETTINGS_MODULE'] = 'hello.settings'import django.core.handlers.wsgiapplication = django.core.handlers.wsgi.WSGIHandler()

4,创建一个新的apache站点

sudo gedit /etc/apache2/sites-available/hello
hello内容
<VirtualHost *:80>    ServerName hello.com    DocumentRoot /opt/wwwroot/hello    <Directory /opt/wwwroot/hello>        Order allow,deny        Allow from all    </Directory>    Alias /robots.txt /opt/wwwroot/hello/robots.txt    Alias /favicon.ico /opt/wwwroot/hello/favicon.ico    Alias /images /opt/wwwroot/hello/images    Alias /static /opt/wwwroot/hello/static    WSGIDaemonProcess hello.com processes=2 threads=15 display-name=%{GROUP}    WSGIProcessGroup hello.com    WSGIScriptAlias / /opt/wwwroot/hello/apache/django.wsgi </VirtualHost>

   由于使用了域名hello.com,应新增一行hosts信息解析该域名。

sudo gedit /etc/hosts
新增一行hosts记录
172.0.0.1   hello.com

   激活hello站点

sudo a2ensite hellosudo service apache2 reload

5,设置完毕打开浏览器进入输入hello.com,就可以看到Django欢迎界面了。