Skip to content
This repository
Newer
Older
100644 67 lines (42 sloc) 1.913 kb
873e1334 »
2008-06-21 edit
1 ---
2 layout: default
3 title: Webpy + Apache with mod_wsgi
4 ---
5
6 # Webpy + Apache with mod_wsgi
7
be7333e9 »
2008-07-01 edit
8 The following steps were tested on Apache-2.2.3 (Red Hat Enterprise Linux 5.2, x86_64), mod_wsgi-2.0.
873e1334 »
2008-06-21 edit
9
10 Note:
11
12 * You may replace 'appname' with your own project name.
13 * You may replace code.py with your own file name.
14 * /var/www/webpy-app found below refers to the path to the directory contains your code.py
15 * /var/www/webpy-app/code.py is the full path to your python file
16
17 Steps:
504eed14 »
2008-06-21 edit
18
a241e709 »
2009-09-03 link
19 * Download and install mod_wsgi from its website: [http://code.google.com/p/modwsgi/](http://code.google.com/p/modwsgi/). It will install a '.so' module in Apache module directory. e.g.
504eed14 »
2008-06-21 edit
20
21 /usr/lib64/httpd/modules/
22
e4e23345 »
2008-06-21 edit
23 * Configure Apache to load mod_wsgi module and your project in httpd.conf:
873e1334 »
2008-06-21 edit
24
e4e23345 »
2008-06-21 edit
25 LoadModule wsgi_module modules/mod_wsgi.so
873e1334 »
2008-06-21 edit
26
59a7847f »
2008-06-21 edit
27 WSGIScriptAlias /appname /var/www/webpy-app/code.py/
873e1334 »
2008-06-21 edit
28
a065b5c5 »
2008-11-28 edit
29 Alias /appname/static /var/www/webpy-app/static/
ca3500eb »
2008-06-21 edit
30 AddType text/html .py
31
e4e23345 »
2008-06-21 edit
32 <Directory /var/www/webpy-app/>
33 Order deny,allow
34 Allow from all
490a3a8d »
2008-06-21 edit
35 </Directory>
36
789a2a74 »
2008-06-21 edit
37 * Sample file 'code.py':
490a3a8d »
2008-06-21 edit
38
39 import web
40
41 urls = (
bc410161 »
2008-11-28 edit
42 '/.*', 'hello',
490a3a8d »
2008-06-21 edit
43 )
44
45 class hello:
bc410161 »
2008-11-28 edit
46 def GET(self):
47 return "Hello, world."
490a3a8d »
2008-06-21 edit
48
49 application = web.application(urls, globals()).wsgifunc()
50
51 * Point your browser to 'http://your_server_name/appname' to verify whether it works for you.
52
b3acf9d4 »
2008-12-01 edit
53 #Note: mod_wsgi + sessions
54
55 If you use sessions with mod_wsgi, you should change you code like below:
56
57 app = web.application(urls, globals())
490a3a8d »
2008-06-21 edit
58
b3acf9d4 »
2008-12-01 edit
59 curdir = os.path.dirname(__file__)
fc6e4d7a »
2010-11-17 Platform indipendent way of building session safe path
60 session = web.session.Session(app, web.session.DiskStore(os.path.join(curdir,'sessions')),)
b3acf9d4 »
2008-12-01 edit
61
62 application = app.wsgifunc()
63
64 #mod_wsgi performance:
65 For mod_wsgi performance, please refer to mod_wsgi wiki page:
bc35e43f »
2011-07-18 fixed link formatting.
66
67 <http://code.google.com/p/modwsgi/wiki/PerformanceEstimates>
Something went wrong with that request. Please try again.