At the moment I can get along with running web.py as an internal server
behind mod_proxy... but something more "mature" wouldn't be too bad.
: )
Is there any obvious pitfall you can think of?
I've managed to configure web.py to run with Apache2, mod_python 3.1.4
and Python 2.4.1.
However I did it on Windows system.
Everything worked as described on http://webpy.org/install page except
for 2 things:
1. After wsgiref installation I had to extract the egg manually to
create an wsgiref subfolder in site-packages.
2. I had to replace wsgiref.modpy_gateway::handler with
wsgiref.modpython_gateway::handler in the .htaccess file. Correct
.htaccess is below.
After that accessing http://localhost/py/codep.py/ gave me 'Hello,
world!'.
My files located in DocumentRoot/py folder:
.htaccess
codep.py
web.py
-- .htaccess start --
AddHandler python-program .py
PythonHandler wsgiref.modpython_gateway::handler
PythonOption application codep::main
-- .htaccess end --
-- codep.py start --
import web
urls = (
'/', 'view'
)
class view:
def GET(self):
print "Hello, world!"
web.internalerror = web.debugerror
main = web.wsgifunc(web.webpyfunc(urls))
-- codep.py end --
Best regards,
Sergey Khenkin
i have installed wsgiref from source via "python setup.py install" and
i already changed modpy_gateway to modpython_gateway. :)
Since my "not found" is a web.py output... installation seems to work
fine so far.
Now i shut down my running webpy process and copied your quoted scripts
to a fresh folder and the result is the same: "not found". The best
thing i could get was the browser offering an empty file for download.
could there be a problem with running as a virtualhost?
Is possible to run it as CGI?
Cheers,
-- Nando Vieira
Sergey Khenkin wrote:
_______________________________________________________
Yahoo! doce lar. Faça do Yahoo! sua homepage.
http://br.yahoo.com/homepageset.html
> Is possible to run it as CGI?
Yes, sure. As CGI and FastCGI according to the docs. Haven't tried that
though.
Best regards,
Sergey Khenkin
| server.modules = ("mod_fastcgi", "mod_rewrite")
server.document-root = "/path/to/root/"
fastcgi.server = ( "/code.py" =>
(( "socket" => "/tmp/fastcgi.socket",
"bin-path" => "/path/to/root/code.py",
"max-procs" => 1
))
)
url.rewrite-once = (
"^/favicon.ico$" => "/static/favicon.ico",
"^/static/(.*)$" => "/static/$1",
"^/(.*)$" => "/code.py/$1",
)|
Cheers,
-- Nando Vieira
Sergey Khenkin wrote:
> But on the docs there's no example of how configuring Apache. Just lighttpd.
> How to apply something similar to Apache?
Well it seems like that.
> | server.modules = ("mod_fastcgi", "mod_rewrite")
> server.document-root = "/path/to/root/"
Install mod_fastcgi (see http://fastcgi.com/)
Install flup (http://www.saddi.com/software/flup/)
Set up DocumentRoot in httpd.conf
Then add this line after other LoadModule lines
LoadModule mod_fastcgi modules/mod_fastcgi.so
and uncomment the line with mod_rewrite if it's commented.
> fastcgi.server = ( "/code.py" =>
> (( "socket" => "/tmp/fastcgi.socket",
> "bin-path" => "/path/to/root/code.py",
> "max-procs" => 1
> ))
> )
Add this line to httpd.conf:
FastCgiServer /path/to/root/code.py -socket /tmp/fastcgi.socket
-maxProcesses 1
> url.rewrite-once = (
> "^/favicon.ico$" => "/static/favicon.ico",
> "^/static/(.*)$" => "/static/$1",
> "^/(.*)$" => "/code.py/$1",
> )|
Those are rewrite rules for mod_rewrite.
They can be configured in .htaccess file in the /path/to/root/
directory or in httpd.conf inside <Directory /path/to/root/> ...
</Directory> element.
See documentation on mod_rewrite.
In .htaccess or httpd.conf add this line
AddHandler fastcgi-script py
Well, I suppose it's something like that :)
The problem for you and me is that we work on Windows and we have an
issue with Flup namely with flup.server.fcgi_base module which uses
socket.fromfd() function.
And if we refer to socket.py we can see that socketpair() and fromfd()
functions are not available on all platforms (e.g. Windows).
So I believe it's impossible to use web.py with FastCGI on Windows at
the moment. It would be great if Aaron shed some light on that.
Best regards,
Sergey Khenkin
I can confirm Sergeys technique on a Mandriva 10.2 box with Apache2,
mod_python2 & python 2.4.1 Heres my notes:
1) Read Graham Dumpletons notes on getting mod_python working with
apache. You can find the notes at
http://www.dscpl.com.au/articles/modpython-001.html
2) View apache log files access_log & error_log in separate consoles
using
'tail -f /path/to/apache/logs' to view what apache reports
*In console 1, type...
$ tail -f /var/log/httpd/access_log
*In console 2 type ...
$ tail -f /var/log/httpd/error_log
3) Use wget to check the output of apache.
'wget http://localhost/py/codep.py'
4) Add 'web.header("Content-Type","text/html; charset=utf-8")'
above the print statement to allow me to view the results in
firefox. You can confirm the number of characters apache
is outputting on a 200 response in conjunction with the 'hello world'
If you dont add the web.header the reponse to the browser will
force a download instead of rendering.
-- codep.py start --
import web
urls = (
'/', 'view'
)
class view:
def GET(self):
web.header("Content-Type","text/html; charset=utf-8")
print "Hello, world!"
web.internalerror = web.debugerror
main = web.wsgifunc(web.webpyfunc(urls))
-- codep.py end --
It think its important to have numerous ways to run web.py apps (do we
have a name) using apache. In the light of Sergeys code example do we
have to modify the lighttpd examples to run in apache?
Regs Peter Renshaw
'wget http://localhost/py/codep.py/'
Forgot the end forward slash.
> But on the docs there's no example of how configuring Apache. Just lighttpd.
> How to apply something similar to Apache?
> | server.modules = ("mod_fastcgi", "mod_rewrite")
> server.document-root = "/path/to/root/"
This looks just like Apache configuration stored in httpd.conf
> fastcgi.server = ( "/code.py" =>
> (( "socket" => "/tmp/fastcgi.socket",
> "bin-path" => "/path/to/root/code.py",
> "max-procs" => 1
> ))
> )
This must be FastCGI configuration.
Haven't tried it yet but http://www.fastcgi.com/ and
http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html should
explain how to configure FastCGI on Apache.
I'll try to do it as soon as I have time.
> url.rewrite-once = (
> "^/favicon.ico$" => "/static/favicon.ico",
> "^/static/(.*)$" => "/static/$1",
> "^/(.*)$" => "/code.py/$1",
> )|
And these are just rewrite rules for mod_rewrite which can be
specified in .htaccess:
RewriteEngine on
RewriteRule ^/favicon.ico$ /static/favicon.ico
...
Best regards,
Sergey Khenkin