Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 67 lines (42 sloc) 1.913 kB
873e133 edit
Bibby authored
1 ---
2 layout: default
3 title: Webpy + Apache with mod_wsgi
4 ---
5
6 # Webpy + Apache with mod_wsgi
7
be7333e edit
dean authored
8 The following steps were tested on Apache-2.2.3 (Red Hat Enterprise Linux 5.2, x86_64), mod_wsgi-2.0.
873e133 edit
Bibby authored
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:
504eed1 edit
Bibby authored
18
a241e70 link
anonymous authored
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.
504eed1 edit
Bibby authored
20
21 /usr/lib64/httpd/modules/
22
e4e2334 edit
Bibby authored
23 * Configure Apache to load mod_wsgi module and your project in httpd.conf:
873e133 edit
Bibby authored
24
e4e2334 edit
Bibby authored
25 LoadModule wsgi_module modules/mod_wsgi.so
873e133 edit
Bibby authored
26
59a7847 edit
Bibby authored
27 WSGIScriptAlias /appname /var/www/webpy-app/code.py/
873e133 edit
Bibby authored
28
a065b5c edit
Bibby authored
29 Alias /appname/static /var/www/webpy-app/static/
ca3500e edit
Bibby authored
30 AddType text/html .py
31
e4e2334 edit
Bibby authored
32 <Directory /var/www/webpy-app/>
33 Order deny,allow
34 Allow from all
490a3a8 edit
Bibby authored
35 </Directory>
36
789a2a7 edit
Bibby authored
37 * Sample file 'code.py':
490a3a8 edit
Bibby authored
38
39 import web
40
41 urls = (
bc41016 edit
Bibby authored
42 '/.*', 'hello',
490a3a8 edit
Bibby authored
43 )
44
45 class hello:
bc41016 edit
Bibby authored
46 def GET(self):
47 return "Hello, world."
490a3a8 edit
Bibby authored
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
b3acf9d edit
Bibby authored
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())
490a3a8 edit
Bibby authored
58
b3acf9d edit
Bibby authored
59 curdir = os.path.dirname(__file__)
fc6e4d7 @sunmountain Platform indipendent way of building session safe path
sunmountain authored
60 session = web.session.Session(app, web.session.DiskStore(os.path.join(curdir,'sessions')),)
b3acf9d edit
Bibby authored
61
62 application = app.wsgifunc()
63
64 #mod_wsgi performance:
65 For mod_wsgi performance, please refer to mod_wsgi wiki page:
bc35e43 @anandology fixed link formatting.
anandology authored
66
67 <http://code.google.com/p/modwsgi/wiki/PerformanceEstimates>
Something went wrong with that request. Please try again.