I have deployed web2py on dreamhost. It's not too hard to do, but the instructions that you find out there aren't that clear and kinda dated.
So, here is an updated step-by-step guide to deploying web2py on dreamhost that I have compiled from various sources and tested myself.
Before you get started though, you'll need to have a VPS. If you don't, you'll have to enable it. Once that is done setup your ssh access (
http://wiki.dreamhost.com/SSH).
The default python on dreamhost is old and we can't install modules.
So, we need to install our own python and virtualenv.
Let's make a directory for python to live in(I'm assuming we are in the home directory here).
NOTE: I'm not sure how this all pans out if you have different users setup on with different domains running under their home directories. I'll just assume you have one user and run all of your domains under that, because that's what I do.
Connect via ssh.
[dreamvps]$
[dreamvps]$ mkdir python
[dreamvps]$ cd python
Feel free to choose some other directory if you really want to.
Now we need to get a newer python.
Time to build and install.
Notice that we configure to our home dir.
[dreamvps]$ cd Python-2.7.6
[dreamvps]$ ./configure --prefix=$HOME/python
[dreamvps]$ make
[dreamvps]$ make install
Assuming there were no errors, check to make sure it works.
[dreamvps]$ ~/python/bin/python
Python 2.7.6 (default, Feb 10 2014, 07:19:04)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Let's append our new python directory to our PATH.
[dreamvps]$ echo 'export PATH=$HOME/python/bin:$PATH' >> ~/.bash_profile
[dreamvps]$ source ~/.bash_profile
With our profile reloaded we should be able run our new build of python directly.
[dreamvps]$ python
Python 2.7.6 (default, Feb 10 2014, 07:19:04)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Time to get virtualenv installed.
[dreamvps]$ ~/python
[dreamvps]$ wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.9.1.tar.gz --no-check-certificate
[dreamvps]$ tar xzf virtualenv-1.9.1.tar.gz
[dreamvps]$ cd virtualenv-1.9.1
[dreamvps]$ python setup.py install
Assuming you had no issues, test to make sure everything is peachy.
[dreamvps]$ virtualenv --version
1.9.1
Let's make a virtualenv to test it out.
[dreamvps]$ cd ~
[dreamvps]$ mkdir env
[dreamvps]$ virtualenv env/test-env
New python executable in env/test-env/bin/python
Installing setuptools............done.
Installing pip...............done.
Now activate it.
[dreamvps]$ source ~/env/test-env/bin/activate
(test-env)[dreamvps]$
If everything seems to be working, we can make a virtualenv for web2py.
(test-env)[dreamvps]$ deactivate
[dreamvps]$ virtualenv env/web2py-env
New python executable in env/web2py-env/bin/python
Installing setuptools............done.
Installing pip...............done.
[dreamvps]$ source ~/env/web2py-env/bin/activate
(web2py-env)[dreamvps]$
(Make sure the root of your web directory is
yourdomain.com/public. This is also in the domain settings where you enable Passenger)
Get whatever modules you need and deactivate the virtualenv.
(web2py-env)[dreamvps]$ easy_install MySQL-python
...
Processing dependencies for MySQL-python
Finished processing dependencies for MySQL-python
(web2py-env)[dreamvps]$ deactivate
[dreamvps]$
Let's get web2py installed.
Download the latest source release and unzip it into your home directory.
[dreamvps]$ cd ~/yourdomain.com
[dreamvps]$ wget http://www.web2py.com/examples/static/web2py_src.zip
[dreamvps]$ unzip web2py_src.zip
[dreamvps]$ rm web2py_src.zip
We need to move wsgihandler.py out of the handler director so web2py can use it.
[dreamvps]$ mv web2py/handlers/wsgihandler.py web2py/.
Now we need to edit wsgihandler.py so it will work.
[dreamvps]$ nano web2py/wsgihandler.py
(you don't have to use nano it's just my preference)
We need to add two lines just after import os to get web2py to use the virtualenv we setup for it (change username and
yourdomain.com to your needs obviously):
...
INTERP = '/home/username/env/web2py-env/bin/python2.7'
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
...
Next, look for this line:
...
path = os.path.dirname(os.path.abspath(__file__))
...
And change it to point directly to the web2py directory:
So it should look like this:
...
import sys
import os
INTERP = '/home/username/env/web2py-env/bin/python2.7'
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
path = '/home/username/yourdomain.com/web2py/'
os.chdir(path)
...
One more step, we need to symlink to the wsgihelper so Passenger can use it. Assuming you are still in the ~/
yourdomain.com directory:
[dreamvps]$ ln -s /home/username/yourdomain.com/web2py/wsgihandler.py passenger_wsgi.py
At this point, you should have a working copy of web2py running. If not, try rebooting your VPS.
Sources:
P.S. Before people ask me why I don't just use pythonanywhere, I do use it for most of my own projects.