Welcome Guest | Login

How to deploy a TurboGears application with Apache and mod_rewrite



This is a wiki article created by HostingRails users. Please login or signup to make edits.


This tutorial will show you how to deploy TurboGears application with apache mod_rewrite (like mod_proxy with lighttpd). Deploying on this way is very easy and HostingRails seems to prepare everything done for you.

If you need to use database, just go to CPanel and choice the database you want to use(MySQL or PostgreSQL). Then create a username and database and join them together. Now database is ready to use.

Next, upload your TurboGears application files to host by FTP, then login to the shell, and jump to the path you just upload files. Now you can edit dev.cfg and prod.cfg. Remember to set dburi, if you use postgresql, leave the hostname blank(ex: postgres://username:password@/dbname). Further, assign server.socket_port to a particular port you like(but not conflict with others) in both dev.cfg and prod.cfg. For more, add following two lines in your .cfg files to avoid causing redirection error:
base_url_filter.on = True
base_url_filter.use_x_forwarded_host = True
OK, now you could simply run "tg-admin sql create" and "./start-prjname.py prod.cfg". Oh yes, it works. However, we still have to set something up with apache to let people visit your website.

Ready? Now change your path to public_html
cd ~/public_html/
And edit .htaccess file
vi .htaccess
Ok, now let's add three lines in it.
RewriteEngine on
RewriteRule ^/static/(.*) /path/to/your/static/$1 [L]
RewriteRule ^(.*) http://127.0.0.1:your_port/$1 [P]
Remember to change the static file path to your application static file path and change the port to you assigned in .cfg files (make sure it matches the port assigned to you by HostingRails).

Is Everything done? Yes, now open your browser and enter your website address. Cheers.



Hello Guest! In order to edit this article you must be an active client with us, please log in or sign up today!






Contributing Author(s):
Olliwang
Brian