How to setup Apache + Python + Django + mod_wsgi

Apache + Python + Django + mod_wsgi Installation Guideline

 

1.  Install Apache

Install the apache follow the instruction.

 

2.  Install Python

Add “D:/software/Python27” and “D:/software/Python27/Scripts” to %Path%

Open “cmd”, and type “python”, you will see below detail:

D:/djworkspace>python

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>>

 

3.  Install Django

Unpackage the Django-1.2.3, then open “cmd”, and type “python setup.py install” to finish the installation.

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import django

>>> django.VERSION

(1, 2, 3, 'final', 0)

 

4.  Setup project

 

 

5.  Configure httpd.conf of Apache

Add below segment to httpd.conf to include external httpd.conf for website:

# Django workspace

Include D://djworkspace//httpd.conf

 

6.  Configure httpd.conf of webserver

Add below segment to httpd.conf to setup the environment of webserver:

<VirtualHost *:80>

    #ServerName www.example.com

    #ServerAlias example.com

    #ServerAdmin webmaster@example.com

    DocumentRoot D://djworkspace//mycompany

    <Directory D://djworkspace//mycompany>

                   Order allow,deny

                   Allow from all

    </Directory>

    WSGIScriptAlias / D://djworkspace//mycompany//django.wsgi

</VirtualHost>

 

If want to host static media by apache, please add below segment under the DocumentRoot:

# Static resource

Alias /robots.txt D://djworkspace//resources//robots.txt

Alias /favicon.ico D://djworkspace//resources//favicon.ico

AliasMatch /([^/]*/.css) D://djworkspace//resources//css//$1

Alias /resources/ D://djworkspace//resources//

<Directory D://djworkspace//resources//>

Order deny,allow

Allow from all

</Directory>

 

7.  Configure mod_wsgi

Create a new file named “django.wsgi” to website, and add below segment to this file:

import os

import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'mycompany.settings'

sys.path.append('D:/djworkspace')

sys.path.append('D:/djworkspace/mycompany')

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

 

8.  Run website

Restart the apache server, then visit your website.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值