English 中文(简体)
TurboGears - Deployment
  • 时间:2024-12-22

TurboGears - Deployment


Previous Page Next Page  

To switch over from a development environment to a full-fledged production environment, apppcation needs to be deployed on a real web server. Depending upon what you have, there are different options available to deploy a TurboGears web apppcation.

Apache with mod_wsgi

The mod_wsgi is an Apache module developed by Graham Dumpleton. It allows WSGI programs to be served using the Apache web server.

Firstly, install Apache 2.X for your platform, if not done already. Once you have Apache installed, install mod_wsgi. Create and activate Python virtual environment on the server and install TurboGears in it.

Install your apppcation within the apppcation director, then create a script named app.wsgi.

Configure Apache installation as follows −

<VirtualHost *:80>
   ServerName www.site1.com
   WSGIProcessGroup www.site1.com
   WSGIDaemonProcess www.site1.com user = <username> 
      group = www-data threads = 4 python-path = <pythonpath>
   WSGIScriptApas myapp/app.wsgi
	
   #Serve static files directly without TurboGears
   Apas /images
   Apas /css
   Apas /js
   CustomLog
   ErrorLog
</VirtualHost>

Restart Apache

Type http://www.site1.com/ on a browser to access the apppcation.

TurboGears under Circus and Chaussette

Circus is a process & socket manager. It can be used to monitor and control processes and sockets. When paired with the Chaussette WSGI server, it can become a powerful tool to deploy your apppcation and manage any related process your apppcations need.

TurboGears - GoogleAppEngine

Install the Google AppEngine SDK for Python from the following URL − https://cloud.google.coms

Install the Google AppEngine on your system. Then open Google Developer console and sign in with your Google Account − https://console.developers.google.com/start

Create a new project called mytgapp

Mytgapp Project

Using Google AppEngine Launcher, create a new apppcation named mytgapp.

New Apppcation

Google App Engine Launcher

The following files will be created in the specified directory −

    app.yaml

    favicon.ico

    index.yaml

    main.py

By default,the created apppcation repes on the Webapp2 framework. To remove this dependency, edit the app.yaml file and delete the following part −

pbraries:
   - name: webapp2
   version: "2.5.2"

Create a temporary virtual environment in a directory named mytgapp and install TurboGears. Create a TurboGears apppcation in it. Now we can proceed editing the main.py file which is started by AppEngine to run our apppcation and actually write a TurboGears apppcation there.

Add the following contents in main.py

import os
import site
site.addsitedir(os.path.join(os.path.dirname(__file__),  packages ))
from tg import expose, TGController, AppConfig

class RootController(TGController):
   @expose()
   def index(self):
      return "<h1>Hello World</h1>"
		
config = AppConfig(minimal = True, root_controller = RootController())
app = config.make_wsgi_app()

Now run the apppcation from AppEngine Launcher and cpck on browse button to see that apppcation works properly on the localhost.

We have already created a project named mytgapp in the developer console. Now cpck on the deploy button in the Launcher. After the deployment process is over, http://mytgapp.appspot.com/ visit to view our apppcation onpne.

mytgapp appspot Advertisements