Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 107 lines (81 sloc) 2.567 kb
bc0f2c3 @ohsc edit
ohsc authored
1 ---
2 layout: default
3 title: Web.py using FastCGI and Apache 2
4 ---
5
6 # Web.py using FastCGI and Apache 2
7
8 #Requirements
9 * Apache 2.x
10 * [mod_fcgid](http://fastcgi.coremail.cn/)
11 * [mod_rewrite](http://httpd.apache.org/docs/2.0/rewrite/)
12 * [Flup](http://trac.saddi.com/flup)
13
14 Note, on CentOS compiling mod_fcgid requires apache-devel be installed (available via yum).
15 #Apache Configuration
16 Replace '/var/www/myapp/' with the path to your apps directory
17
18 LoadModule rewrite_module modules/mod_rewrite.so
19 LoadModule fcgid_module modules/mod_fcgid.so
20
21 SocketPath /tmp/fcgidsock
22 SharememPath /tmp/fcgid_shm
23
24 Alias /static "/var/www/myapp/static"
25 Alias / "/var/www/myapp/"
26 <Directory "/var/www/myapp/">
27 allow from all
28 SetHandler fcgid-script
29 Options +ExecCGI
30 AllowOverride None
31 <IfModule mod_rewrite.c>
32 RewriteEngine on
33 RewriteBase /
34 RewriteCond %{REQUEST_URI} !^/icons
35 RewriteCond %{REQUEST_URI} !^/favicon.ico$
36 RewriteCond %{REQUEST_URI} !^(/.*)+code.py/
37 RewriteRule ^(.*)$ code.py/$1 [PT]
38 </IfModule>
39 </Directory>
40
41 <Directory "/var/www/myapp/static">
42 allow from all
43 AllowOverride None
44 Options -ExecCGI
45 SetHandler None
46 </Directory>
47
48
49
50
51 #Hello World
52 Note the following line is required:
53 web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
54
55 #!/usr/bin/python
56
57 import web
58
59 urls = ("/.*", "hello")
60 app = web.application(urls, globals())
61
62 class hello:
63 def GET(self):
64 return 'Hello, world!'
65
66 web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
67 if __name__ == "__main__":
68 app.run()
69
70
71 #Run
72 1. Start your server.
73 1. Open your application with your browser
74 1. To confirm your application is running try:
75
76 <code>
77 ps aux | grep code.py
78 </code>
79
80 #Troubleshooting
81
82 <br>
83 ###Check your apache error log for information!
84
85 <br>
86 ##Common problems
87 <br>
88
89 ###File permissions.
90 You might see error code 255 in your logs.
91 Ensure the directory is readable and that code. py is executable:
92
93 <code>
94 chmod +x code.py
95 </code>
96
97 ###404 Not Found.
98 Is your Alias path correct in your apache configuration?
99
100 ###Other problems
101 Web.py spawns http://0.0.0.0:8080, dies unexpectedly, or returns nothing.
102 Did you add this line?
103 <pre>
104 web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
105 </pre>
106 #Misc
107 After updating your application you may need to restart your web server to see the changes.
Something went wrong with that request. Please try again.