Setting up Web2Py in a Subdirectory using FastCGI
This documents the steps I did in order to get Web2Py running on dreamhost.com hosting service in a subdirectory using FastCGI.
Python 2.5 virtualenv
Install Python 2.py and virtualenv on Dreamhost
In this example Python 2.5 is installed to /home/yourdomain/local/bin
.
Use setuptools/easy_install to add MySQL and flub;
[dreamhost] $ wget http://peak.telecommunity.com/dist/ez_setup.py
[dreamhost] $ /home/yourdomain/local/bin/python ez_setup.py
Install flup
(and MySQL
if you need it):
[dreamhost] $ ./local/bin/easy_install MySQL-python
[dreamhost] $ ./local/bin/easy_install flup
web sub-directory
The web directory of the hosting service is /home/yourdomain/yourdomain.com
. The URL for this is http://www.yourdomain.com.
The web2py directory will be in a subdirectory, /home/yourdomain/yourdomain.com/web2py
, http://www.yourdomain.com/web2py.
Get and Unzip web2py
Copy or check out web2py;
[dreamhost] $ wget http://mdp.cti.depaul.edu/examples/static/web2py_src.zip
[dreamhost] $ unzip web2py_src.zip -d /home/yourdomain/yourdomain.com
This will make a sub-directory, /home/yourdomain/yourdomain.com/web2py
.
Create web2py defaults
Run web2py.py
to have it create example apps and password file:
[dreamhost] $ /home/yourdomain/local/bin/python web2py.py
The profile/pstats modules cannot be found
Please install the python-profiler package
web2py Enterprise Web Framework
Created by Massimo Di Pierro, Copyright 2007-2010
Version 1.76.1 (2010-03-01 19:56:55)
Database drivers available: SQLite3, MySQL
Starting cron...
choose a password:
Enter in a password and hit enter;
please visit:
http://127.0.0.1:8000
use "kill -SIGTERM 21310" to shutdown the web2py server
Stop the script with Ctrl-C
.
Redirect and .htaccess
Create a file web2py.fcgi
at the root of the web2py directory with the following content:
#!/home/yourdomain/local/bin/python
import sys
from flup.server.fcgi_fork import WSGIServer
import gluon.main
application=gluon.main.wsgibase
## or
# application=gluon.main.wsgibase_with_logging
WSGIServer(application).run()
Note that the 1st line has the full path to the Python 2.5 virtualenv location.
Make this file executable:
[dreamhost] $ chmod +x web2py.fcgi
Create .htaccess
file:
RewriteEngine On
RewriteBase /
RewriteRule ^web2py\.fcgi/ - [L]
RewriteRule ^(.*)$ web2py.fcgi/$1 [L]
Fix urls
Rename routes.example.py
to routes.py
and edit:
routes_in=(('/web2py/(?P<a>.*)','/\g<a>'),)
...
routes_out=(('/(?P<a>.*)','/web2py/\g<a>'),)
Now web2py should be accessable through the URL http://www.yourdomain.com/web2py.
Addendum - web2py admin page
The web2py admin page does not work without changing code in appadmin.py
file.
Addendum - Command Line testing
Running from the command line.
The web2py.fcgi
script will throw an exception because the REMOTE_ADDR
is not available. Set this on the command line and run the dispatch script to verify web2py runs;
export REMOTE_ADDR=192.168.0.1
./web2py.fcgi
Comments (2)
0
rahuld 14 years ago
0
rahuld 14 years ago