Skip to content
This repository

Added another deployment case. #28

Merged
merged 2 commits into from almost 2 years ago

2 participants

Marios Zindilis Aaron Swartz
Marios Zindilis

These two commits add a deployment case for web.py on Ubuntu with Apache and mod_wsgi, and change the cookbook/index.md to list the new case. You can preview the Markdown rendered at http://notepag.es/jbOKGf

Aaron Swartz aaronsw merged commit e5b1838 into from
Aaron Swartz aaronsw closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 86 additions and 1 deletion. Show diff stats Hide diff stats

  1. +2 1  cookbook/index.md
  2. +84 0 cookbook/mod_wsgi-apache-ubuntu.md
3  cookbook/index.md
Source Rendered
@@ -85,7 +85,8 @@ _Other languages:_ [简体中文](/cookbook/index.zh-cn) | [日本語](/cookbook
85 85 * [Fastcgi deployment through Apache](/cookbook/fastcgi-apache)
86 86 * [CGI deployment through Apache](/cookbook/cgi-apache)
87 87 * mod_python deployment through Apache (requested)
88   -* [mod_wsgi deployment through Apache](/cookbook/mod_wsgi-apache )
  88 +* [mod_wsgi deployment through Apache on Red Hat](/cookbook/mod_wsgi-apache)
  89 +* [mod_wsgi deployment through Apache on Ubuntu](/cookbook/mod_wsgi-apache-ubuntu)
89 90 * [mod_wsgi deployment through Nginx](/cookbook/mod_wsgi-nginx )
90 91 * [Fastcgi deployment through Nginx](/cookbook/fastcgi-nginx)
91 92 * [PyISAPIe deployment through IIS7/IIS6](/cookbook/iis7_iis6_windows_pyisapie)
84 cookbook/mod_wsgi-apache-ubuntu.md
Source Rendered
... ... @@ -0,0 +1,84 @@
  1 +---
  2 +layout: default
  3 +title: Webpy + Apache with mod_wsgi on Ubuntu
  4 +---
  5 +
  6 +# Webpy + Apache with mod_wsgi on Ubuntu
  7 +
  8 +The following steps were tested on:
  9 +
  10 +1. Ubuntu 10.04, with Apache 2.2.16 and mod_wsgi 3.2-2, and
  11 +2. Ubuntu 12.04, with Apache 2.2.22 and mod_wsgi 3.3-4.
  12 +
  13 +The same steps should work in other versions of Ubuntu as well.
  14 +
  15 +Note:
  16 +
  17 +* You may replace `appname` with your own project name.
  18 +* You may replace `code.py` with your own file name.
  19 +* `/var/www/webpy-app` found below refers to the path to the directory contains your code.py.
  20 +* `/var/www/webpy-app/code.py` is the full path to your python file.
  21 +
  22 +### Steps:
  23 +
  24 +1. Install mod_wsgi:
  25 +
  26 + sudo apt-get install libapache2-mod-wsgi
  27 +
  28 + This will install a `.so` module in Apache's **module directory**:
  29 +
  30 + /usr/lib/apache2/modules/mod_wsgi.so
  31 +
  32 + It will also automatically configure Apache to load the `mod_wsgi` module upon restart. You can confirm the presence of the module in Apache's **available modules directory**…
  33 +
  34 + /etc/apache2/mods-available/wsgi.conf
  35 + /etc/apache2/mods-available/wsgi.load
  36 + …as well as in Apache's **enabled modules directory**:
  37 +
  38 + /etc/apache2/mods-enabled/wsgi.conf
  39 + /etc/apache2/mods-enabled/wsgi.load
  40 +
  41 +2. Configure a website on Apache to load the `mod_wsgi` module. This can either be your default website, or another Virtual Host, which you can create by copying `/etc/apache2/sites-available/default` to something like `/etc/apache2/sites-available/my-website`. Add the following lines, under the `DocumentRoot` directive:
  42 +
  43 + WSGIScriptAlias /appname /var/www/webpy-app/code.py/
  44 + AddType text/html .py
  45 +
  46 + Typically, the above two lines are the only ones necessary to serve a website built with web.py. Most probably, you will additionally need to define a subdirectory in your application, from which static files will be served. In this case, add:
  47 +
  48 + Alias /appname/static /var/www/webpy-app/static/
  49 +
  50 + After you have finished editing your website definition, you need to enable it (in case it is not already enabled). Do:
  51 +
  52 + sudo a2ensite my-website
  53 +
  54 +3. Finally, create a sample file `/var/www/webpy-app/code.py`:
  55 +
  56 + import web
  57 +
  58 + urls = (
  59 + '/.*', 'hello',
  60 + )
  61 +
  62 + class hello:
  63 + def GET(self):
  64 + return "Hello, world."
  65 +
  66 + application = web.application(urls, globals()).wsgifunc()
  67 +
  68 +4. Point your browser to 'http://your_server_name/appname' to verify whether it works for you.
  69 +
  70 +### Note: mod_wsgi + sessions
  71 +
  72 +If you use sessions with `mod_wsgi`, you should change you code like below:
  73 +
  74 + app = web.application(urls, globals())
  75 +
  76 + curdir = os.path.dirname(__file__)
  77 + session = web.session.Session(app, web.session.DiskStore(os.path.join(curdir,'sessions')),)
  78 +
  79 + application = app.wsgifunc()
  80 +
  81 +### mod_wsgi performance:
  82 +For mod_wsgi performance, please refer to mod_wsgi wiki page:
  83 +
  84 +<http://code.google.com/p/modwsgi/wiki/PerformanceEstimates>

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.