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

From your home folder, install virtualenv. This will allow us to add modules to Python by creating a virtual environment in our home folder:

wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.4.5.tar.gz
tar xzf virtualenv-1.4.5.tar.gz
python2.5 virtualenv-1.4.5/virtualenv.py $HOME/local

Add your new ~/local/bin folder to the beginning of your PATH so it takes priority:

PATH="$HOME/local/bin:$PATH"    
export PATH

Now add the two lines above to your .bash_profile so this will be set automatically when you login:

nano .bash_profile

After adding the lines, save the file by hitting Ctl-x, y, ENTER

Install the MySQL module if you need it:

easy_install MySQL-python

Download the source release, unzip it and move the contents directly into your domain's root folder (yourdomain.com).

cd
wget http://www.web2py.com/examples/static/web2py_src.zip
unzip web2py_src.zip
mv web2py/* yourdomain.com/

Change your root web directory to yourdomain.com/public at panel.dreamhost.com and enable Passenger on your Dreamhost account:

alt text

Edit wsgihandler.py and add these two lines near the top after 'import os' to redirect requests to virtualenv's python2.5:

...
import os
INTERP = "/home/username/local/bin/python2.5"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
...

Symlink wsgihandler.py to passenger_wsgi.py with the following command:

ln -s wsgihandler.py passenger_wsgi.py

That's it! A word of warning though...this seems to break the Dreamhost stats and myPHPadmin.

To restart your app, create or modify the file tmp/restart.txt in domain's root folder.


Links:

Dreamhost WIKI

Phusion Passenger

Related slices

Comments (3)

  • Login to post



  • 0
    jtk 8 years ago

    Does Dreamhost require you to use a VPS to make this work?  This posting says so, but I don't see why.  I'm able to get Flask running using similar code in passenger_wsgi.py, but with web2py, Passenger times out, saying it didn't get a response from the web application in time.

    replies (1)
    • jtk 8 years ago

      Answering my own question... The line "sys.stdout = sys.stderr" in passenger_wsgi.py breaks Passenger. This problem is documented by Passenger ("don't overwrite stdout"), so I'm not sure how this code worked in the first place, unless the change to Passenger is more recent.

      The change (commenting out the stdout assignment) fixes the startup problem, although I don't know what, if any, impact the change might have on web2py behavior.


  • 0
    babu 14 years ago
    Thank you.. worked for me. Additionally, I had to run easy_install virtualenv to get the virtualenv binary into my local/bin. Was the 3rd step supposed to put virtualenv.py into local/bin?

  • 0
    mrfreeze 14 years ago
    Yes, the third step should have done that. It was taken from here: http://wiki.dreamhost.com/Python#Virtualenv

Hosting graciously provided by:
Python Anywhere