Knowledge Base

How to install TurboGears on a shared hosting account

This article describes how to install the Python-based TurboGears web application framework on a shared hosting account.

Installing TurboGears

To install TurboGears, you first create a virtual environment for Python by using the virtualenv tool. After you activate the virtual environment, you can use the pip installer to install TurboGears.

  1. Log in to your account using SSH.
  2. To create and activate the virtual environment, type the following commands:
    cd ~
    virtualenv turbogears
    source turbogears/bin/activate

    These commands create a virtual environment named turbogears, and subsequent commands in this article assume that the environment is named turbogears. If you use a different environment name, make sure you replace all occurrences of turbogears with your own environment name.

  3. To install TurboGears, type the following commands:

    pip install flup
    pip install -i tg.devtools
  4. TurboGears is now installed and ready to be configured.

Configuring TurboGears

You have installed TurboGears. Now let's set up a test project and configure it to make sure that TurboGears is working correctly:

  1. To set up a test project, type the following commands.
    cd ~/turbogears/
    paster quickstart mysite

    These commands create a project named mysite, and subsequent commands and settings in this article assume that the project is named mysite. If you use a different project name, make sure you replace all occurrences of mysite with your own project name.

  2. At the Enter package name prompt, press ENTER to accept the default value.

  3. At the Would you prefer to use an alternative template system? prompt, press ENTER to accept the default value.

  4. At the Do you need authentication and authorization in this project? prompt, press ENTER to accept the default value.

  5. To configure the project, type the following commands:

    cd mysite
    python develop
    paster setup-app development.ini
  6. Create an .htaccess file in the /home/username/public_html directory that contains the following lines:

    Options +ExecCGI
    AddHandler fcgid-script .fcgi
    RewriteEngine On
    RewriteRule   ^(dispatch\.fcgi/.*)$  - [L]
    RewriteRule   ^(.*)$  dispatch.fcgi/$1 [L]
  7. Create a dispatch.fcgi file in the public_html directory that contains the following lines. Replace all instances of username with your own account username. Also, make sure that the turbogears value specifies the correct path to the virtual environment you created in the Installing TurboGears procedure above:

    # Set up the virtualenv:
    import os
    os.environ.setdefault('PATH', '/bin:/usr/bin')
    os.environ['PATH'] = '/home/username/turbogears/bin:' + os.environ['PATH']
    os.environ['VIRTUAL_ENV'] = '/home/username/turbogears/bin'
    os.environ['PYTHON_EGG_CACHE'] = '/home/username/turbogears/bin'
    inifile = 'development.ini'
    turbogears = '/home/username/turbogears/mysite'
    import sys
    # Add a custom Python path:
    sys.path.insert(0, "/home/username/public_html/")
    from paste.deploy import loadapp
    wsgi_app = loadapp('config:' + turbogears + '/' + inifile)
    from flup.server.fcgi import WSGIServer

    Although this example runs the project from the document root (public_html) directory, you do not have to configure it this way. You can create a subdirectory beneath the public_html directory and place the .htaccess and dispatch.fcgi files in it instead. If you do this, make sure you modify the os.chdir statement in the dispatch.fcgi file to use the correct path.

  8. Type the following command to set the correct permissions for the dispatch.fcgi file:

    chmod 755 ~/public_html/dispatch.fcgi
  9. Use your browser to go to, where represents your domain name. You should see the Welcome to TurboGears page.

More Information

For more information about TurboGears, please visit