This article describes how to install the Python-based TurboGears web application framework on a shared hosting account.
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.
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.
To install TurboGears, type the following commands:
pip install flup pip install -i http://tg.gy/222 tg.devtools
TurboGears is now installed and ready to be configured.
You have installed TurboGears. Now let's set up a test project and configure it to make sure that TurboGears is working correctly:
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.
At the Enter package name prompt, press ENTER to accept the default value.
At the Would you prefer to use an alternative template system? prompt, press ENTER to accept the default value.
At the Do you need authentication and authorization in this project? prompt, press ENTER to accept the default value.
To configure the project, type the following commands:
cd mysite python setup.py develop paster setup-app development.ini
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]
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:
#!/home/username/turbogears/bin/python # 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' os.chdir('/home/username/public_html') 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 WSGIServer(wsgi_app).run()
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.
Type the following command to set the correct permissions for the dispatch.fcgi file:
chmod 755 ~/public_html/dispatch.fcgi
Use your browser to go to http://www.example.com, where example.com represents your domain name. You should see the Welcome to TurboGears page.
For more information about TurboGears, please visit http://www.turbogears.org.