HOWTO: Installing TurboGears app on shared hosting
January 23rd, 2006Here is a recipe I used to install TurboGears pre-0.9 release (yes, the trunk) on a hosted environment (python-hosting.com). The information is taken partly from this TxD thread, DocumentationPlayground and Turbogears Google group archives.
The HOWTO describes how to install TurboGears app on a shared hosting account, whereas Apache forwards HTTP requests to the CherryPy server and installation files is sandboxed to user’s homedir (vs. usual system-wide setup).
1. Prepare non-root python environment
This is easy with Ian Bicking’s script:
$ wget http://svn.colorstudy.com/home/ianb/non_root_python.py $ python2.4 non_root_python.py
This copies system Python2.4 files to your ~/bin, ~/lib/python2.4 and ~/include directories. The “non-root” python executable will reside in ~/bin.
2. Install TurboGears itself
$ svn co http://www.turbogears.org/svn/turbogears/trunk turbogears $ cd turbogears $ cd thirdparty/cherrypy/ $ ~/bin/easy_install -D -s ~/bin/ . $ cd - $ cd thirdparty/kid/ $ ~/bin/easy_install -D -s ~/bin/ . $ cd - $ ~/bin/easy_install -D -s ~/bin/ .
Note that I also had to installKid and Cheetah from SVN; this is currently required for TG to operate properly. To verify the install try to run ~/bin/tg-admin command.
3. Install Turbogears application
Next step is to install your application. If you’re using an egg (and I think there is no valid reason you shouldn’t) it’s simply a matter of running ~/bin/easy_install -s ~/bin TheApp-1.0.egg
. Btw, to build an egg just run setup.py bdist_egg
from within your development copy.
4. Configure the application
This is a matter of writing proper prodcfg.py. The settings to pay attention to are: sqlobject.dburi, server.socket_port and server.log_file. In a shared hosting setup, the socket_port and log directory to use are given by the hoster so just make sure you’ve specified them correctly.
When running proxied behind Apache you will also need to add the following to the setup:
path(\"/\") base_url_filter.on = True base_url_filter.useXForwardedHost = True
This ensures CherryPy will use “X-Forwarded-Host” header set by Apache to figure out publicly-visible address of the application.
5. Running the application
One final tidbit is how the application is started and run. On python-hosting.com they use a special “launching” .cgi that need to be updated to use your start-app.py script (which is put into ~/bin by setuptools).
That’s it. It worked for me but if you run into a problem don’t hesitate to ask.