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.
- 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:
#!/home/youruserhere/run/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()
- 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!
Easy way using WSGI Here are the steps I took to get web2py working with wsgi:
- I installed my own python distro so I could use 2.6. I don't know if this is neccessary.
- Created a subdomain like: web2py.mydomain.com. When creating the new domain, make sure to check enable "Ruby on Rails Passenger" or mod_rails.
- 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.
- I created a symlink as follows: ln -s wsgihandler.py passenger_wsgi.py. This is neccessary because the rails stuff looks for this file.
- 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.
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.
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
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:127.0.0.1:8080 email@example.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 127.0.0.1:8080 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(http_host), socket.gethostbyname (socket.gethostname ()),
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).
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!!!
Different versions of Python
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 sunaudiodev
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:127.0.0.1:8001 firstname.lastname@example.org
- 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: