Passenger WSGI setup with pyenv on Dreamhost for Web2Py

I have been using fastcgi+flup (link) to run my web2py apps on shared Dreamhost hosting. But the speed was really mediocre. Dreamhost recommends Passenger WSGI for python application.

After hours of research and testing, I would like to share my experience using pyenv + passenger wsgi + web2py on Dreamhost shared hosting as of 08.2017

What I did differently than most guides online is that I only have to edit .htaccess file (in domain root folder) with: (Credit: ASO)

PassengerEnabled on
PassengerAppRoot /home/%USER%/
PassengerPython /home/%USER%/.pyenv/shims/python

Most importantly and strangely, I didn’t need to modify passenger_wsgi.py (handlers/wsgihandler.py) at all. Most guides online (this; this; and many others) require adding two lines after import os, such as this one:

INTERP = "/home/%USER%/.pyenv/shims/python"
#INTERP is present twice so that the new Python interpreter knows the actual executable path
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)

But I couldn’t make it work if I modify passenger_wsgi.py. It seems .htaccess is sufficient to specify pyenv environment.

Some guides also suggest make a pyenv “virtualenv” within app folder, I found it is not required.

Assuming you already know:

  1. how to use web2py
  2. how to use pyenv on Dreamhost
  3. Read about Passenger on Dreamhost

This is what I did:

  1. Enable passenger on Dreamhost panel. A folder public will be created. Don’t worry.
  2. Put web2py files into your domain root folder, which is parent folder of public
  3. cp handlers/wsgihandler.py passenger_wsgi.py
  4. Create/modify .htaccess in domain root folder as described above.
  5. Created tmp/ folder under my web root folder, did a touch restart.txt to get passenger to reload

Your web2py site should now load in your browser. If you use free “Let’s Encrypt” SSL from Dreamhost panel, you should be able to verify your pyenv python environment from admin interface by accessing https. I did verify mine.

I am not sure ssh tunnel method could serve as verification, because you are serving admin from a separate web2py instance running from your shell.

Hope this will help fellow web2py users. Thank all the web2py team for providing web2py.

Leave a Reply

Your email address will not be published. Required fields are marked *