Permalink
Newer
Older
100644 105 lines (80 sloc) 3.06 KB
Mar 10, 2008
1
---
2
layout: default
3
title: Webpy + LightTTPD with FastCGi
4
---
5
6
# Webpy + LightTTPD with FastCGi
7
Mar 13, 2008
8
The following applies on lighttpd version 1.4.18
Mar 10, 2008
9
Mar 10, 2008
10
##Note:
Mar 10, 2008
11
* You may replace <code>code.py</code> with your own file name.
12
* <code>/path-to/webpy-app</code> found below refers to the path to the directory contains your <code>code.py</code>
13
* <code>/path-to/webpy-app/code.py</code> is the full path to your **python file**
14
Mar 13, 2008
15
If you are not certain what version you are running simply type: <code>lighttpd -v</code> at your console.
Mar 10, 2008
16
Mar 13, 2008
17
Note: Earlier version of lighttpd may organize the .conf files differently. Yet, the same principles applied on them as well.
Mar 10, 2008
18
19
###ligghttpd Configuration under Debian GNU/Linux
Mar 10, 2008
20
21
<pre>
22
Files and Directories in /etc/lighttpd:
23
---------------------------------------
24
25
lighttpd.conf:
26
main configuration file
27
28
conf-available/
29
This directory contains a series of .conf files. These files contain
30
configuration directives necessary to load and run webserver modules.
31
If you want to create your own files they names should be
32
build as nn-name.conf where "nn" is two digit number (number
33
is used to find order for loading files)
34
35
conf-enabled/
36
To actually enable a module for lighttpd, it is necessary to create a
37
symlink in this directory to the .conf file in conf-available/.
38
39
Enabling and disabling modules could be done by provided
40
/usr/sbin/lighty-enable-mod and /usr/sbin/lighty-disable-mod scripts.
Mar 10, 2008
41
</pre>
Mar 10, 2008
42
Mar 10, 2008
43
<strong>
Mar 10, 2008
44
For web py you should enable mod_fastcgi and mod_rewrite, thus run: <code>/usr/sbin/lighty-enable-mod</code> and supply <code>fastcgi</code>
45
(mod_rewrite will be enabled within <code>10-fastcgi.conf</code> file as you will see in a moment).
Mar 10, 2008
46
Mar 10, 2008
47
##Below are instructions for the following files:
Mar 10, 2008
48
* <code>/etc/lighttpd/lighttpd.conf</code>
49
* <code>/etc/lighttpd/conf-available/10-fastcgi.conf</code>
50
* <code>code.py</code>
Mar 10, 2008
51
52
<code>/etc/lighttpd/lighttpd.conf</code>
53
54
<pre>
55
server.modules = (
56
"mod_access",
57
"mod_alias",
58
"mod_accesslog",
59
"mod_compress",
60
)
Mar 10, 2008
61
server.document-root = "/path-to/webpy-app"
Mar 10, 2008
62
</pre>
63
64
In my case I used postgresql and therefore runs lighttpd as postgres in order to grant permissions to the database, therefore I added the line:
65
66
<pre>
67
server.username = "postgres"
68
</pre>
69
Mar 10, 2008
70
<code>/etc/lighttpd/conf-available/10-fastcgi.conf</code>
Mar 10, 2008
71
Mar 10, 2008
72
<pre>
Mar 10, 2008
73
server.modules += ( "mod_fastcgi" )
74
server.modules += ( "mod_rewrite" )
Mar 10, 2008
75
76
fastcgi.server = ( "/code.py" =>
77
(( "socket" => "/tmp/fastcgi.socket",
Mar 10, 2008
78
"bin-path" => "/path-to/webpy-app/code.py",
Mar 10, 2008
79
"max-procs" => 1,
80
"bin-environment" => (
81
"REAL_SCRIPT_NAME" => ""
82
),
83
"check-local" => "disable"
84
))
85
)
86
87
url.rewrite-once = (
88
"^/favicon.ico$" => "/static/favicon.ico",
89
"^/static/(.*)$" => "/static/$1",
90
"^/(.*)$" => "/code.py/$1",
91
)
92
</pre>
93
Mar 10, 2008
94
<code>/code.py</code>
95
At the top of the file add:
Mar 10, 2008
96
97
<pre>
98
#!/usr/bin/env python
99
</pre>
100
101
and don't forget to make it executable (otherwise you will get a "permission denied" error):
102
103
<pre>
104
$ chmod 755 /path-to/webpy-app/code.py
Mar 10, 2008
105
</pre>