From DreamHost
Jump to: navigation, search
DreamHost does not directly support any of the features described on this page and is not responsible for keeping this content updated or accurate. Use at your own risk!
There may be additional information on the talk page.

Web2py is a Python web framework. It seems very user-friendly and has a feature I haven't seen on similar ones: in-page code editing. This means you can manage your entire application via web.

Unfortunately it has limited installation instructions, at least for shared-hosting environments. Thus the creation of this page.

Installation Methods

Fast CGI

Necessary steps:

  • Install Python 2.5 by following this wiki page
  • Install setuptools
  • Run easy_install Flup
  • Download and extract web2py
  • Run python web2py.py to create the necessary framework files
  • Create a file dispatch.fcgi at the root of web2py directory with the following content:
import sys
from flup.server.fcgi_fork import WSGIServer
import gluon.main
## or
# application=gluon.main.wsgibase_with_logging
  • make this file executable by typing chmod +x dispatch.fcgi
  • create or add the following lines to .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^dispatch\.fcgi/ - [L]
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]

Now try and access the sub/domain on your browser and it should work!

See also: http://www.web2pyslices.com/main/slices/take_slice/68

Passenger WSGI

Easy way using WSGI Here are the steps I took to get web2py working with wsgi:

  1. I installed my own python distro so I could use 2.6. I don't know if this is neccessary.
  2. Created a subdomain like: web2py.mydomain.com. When creating the new domain, make sure to check enable "Ruby on Rails Passenger" or mod_rails.
  3. I svn checkedout a fresh web2py right into my domain's root (/home/username/web2py.mydomain.com). Note, this isn't the public directory. The previous step requires you to set a subdirectory as the public directory.
  4. I created a symlink as follows: ln -s wsgihandler.py passenger_wsgi.py. This is neccessary because the rails stuff looks for this file.
  5. And last, but not least, so that wsgihandler uses my 2.6 version of python, I added the following to wsgihandler.py near to the top:
import sys
import os

INTERP = "/home/username/opt/bin/python"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)

One More Thing I fought with getting web2py to work with passenger for ages. I finally figured out that the line

 sys.stdout = sys.stderr

in the wsgihandler.py handler caused the script to not start. Not sure of the consequences of taking it out (yet) but I can assure you that with it in there passenger will just time out.

See also: http://www.web2pyslices.com/main/slices/take_slice/1

For more info on this subject, see Passenger_WSGI

Accessing Admin Pages

Once you have installed web2py, you will immediately find out you cannot actually access the admin pages. This is due to security restrictions that are implemented directly into web2py. To fix this problem you need to choose form a few options.

Setup SSL

Ideally this would be what you want to do, however with Dreamhost this requires you to have a fixed IP for your site. Additionally, if you want you can pay for a certified SSL key or you will have to set one up as self certified (not terribly difficult)

For more information see:

Setup an SSH tunnel

Method #1

web2py does not require an SSL connect if you are connecting from a local machine. However, you can make it think that you are a local machine by setting up an SSH tunnel to the dreamhost server.

This requires that you have a user with Shell access enabled (see SSH) but you should already have that since you made it this far. Also, remember that you need to do this every time you wish to access the admin screens.

Logged into dreamhost and in the proper directory run:

python web2py.py -p 8001 -a "password"

Note that 'password' is actually your password to login so feel free to change it.

You may get an error and if you do the most likely problem is that port 8001 is already in use. If that's the case pick a different port (50000+ seems to be successful)

Next to get the tunnel working in bash shell script you can type:

ssh -L 8001: username@server.dreamhost.com

Note that the 8001 should be the same value as you successfully used to start the new instance of web2py. So replace it with whatever value you succeeded with.

Once this is done type into your browser and you should see the default index screen. Be sure to remember whatever password you used above as it is now your admin login password.

For more information see:

Note that this may still result in problems on hosts which have multiple interfaces. In that case, add the following line (3rd line below)

   hosts = (http_host, socket.gethostname(),
            socket.gethostbyname (socket.gethostname ()),

to controllers/appadmin.py

Disable security

This is method is not recommended Doing this will, as stated, disable all the security features of web2py.

The security is however easy to circumvent by editing /applications/admin/models/access.py

Also, for the database administration to work you will have to edit /applications/your_app_name/controllers/appadmin.py (you'll have to do this for every app).

comment lines:

elif remote_addr not in hosts:
   raise HTTP(200, T('appadmin is disabled because insecure channel'))

and duplicate parameters_8000.py as parameters_80.py.

But note that this is not recomended!!!

Other Issues

Different versions of Python

python 2.6

I installed python 2.6.1 and although it complained during the make stage it is working fine and actually seems faster than 2.5.2. The modules it wasn't able to build were:

_bsddb             _tkinter           bsddb185        
bz2                dbm                readline        

some Comments

After struggling with the above instructions for quite some time, I thought I'd share some comments about it.

  • Because I am running Passenger, the web directory is in the 'public' folder. (I didn't really understand the instructions under "Passenger WSGI" above). I put 'dispatch.fcgi' inside the web2py folder, and .htaccess one level up inside the 'public' folder. Note that I had to change .htaccess to:
RewriteEngine On
RewriteBase /
RewriteRule ^web2py/dispatch\.fcgi/ - [L]
RewriteRule ^(.*)$ web2py/dispatch.fcgi/$1 [L]
  • In the instructions above for setting up an ssh tunnel, it didn't work for me until I changed it to:
ssh -L 8001: username@server.dreamhost.com
  • Also, another way to see the administrative pages without SSL, SSH tunnel, or disabling security,

is to use lynx! After you've started web2py, call lynx from within a dreamhost terminal: