If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

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

Related slices

Comments (2)

  • Login to post



  • 0
    rahuld 14 years ago
    Hi I am confused about this --> export REMOTE_ADDR=192.168.0.1 --? What does this signify. Do we need to do this every time? What is its use.. ---> Although after keying this in it does not show me any REMOTE_ADD Error. ./web2py.fcgi --- After setting up this and following the steps it shows me this in the command line --- -bash-3.2$ export REMOTE_ADDR=192.168.0.1 -bash-3.2$ ./web2py.fcgi WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI! WSGIServer: missing FastCGI param SERVER_NAME required by WSGI! WSGIServer: missing FastCGI param SERVER_PORT required by WSGI! WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI! Status: 303 SEE OTHER Content-Type: text/html; charset=UTF-8 Location: /web2py/welcome/default/index Content-Length: 73 You are being redirected here-bash-3.2$ ------------ What are the next steps that we can follow? will it access the url? Also upon accessing the url it shows me the folder listing not the welcome page what am I doing wrong??????? Please rever ASAP Thanks Rahul D

  • 0
    rahuld 14 years ago
    Also if I access the url [http://www.flockbird.com/web2py/] It throws the below error - Note I am on CPANEL ================ Not Found The requested URL /web2py.fcgi/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.3.1 Server at www.flockbird.com Port 80 --------

Hosting graciously provided by:
Python Anywhere