From 7792f1feda63b16835755dc0c14c2d06debb8e75 Mon Sep 17 00:00:00 2001 From: Marios Zindilis Date: Mon, 30 Jul 2012 01:21:42 +0300 Subject: [PATCH 1/2] Documented new deployment case --- cookbook/mod_wsgi-apache-ubuntu.md | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 cookbook/mod_wsgi-apache-ubuntu.md diff --git a/cookbook/mod_wsgi-apache-ubuntu.md b/cookbook/mod_wsgi-apache-ubuntu.md new file mode 100644 index 00000000..5f9d2371 --- /dev/null +++ b/cookbook/mod_wsgi-apache-ubuntu.md @@ -0,0 +1,84 @@ +--- +layout: default +title: Webpy + Apache with mod_wsgi on Ubuntu +--- + +# Webpy + Apache with mod_wsgi on Ubuntu + +The following steps were tested on: + +1. Ubuntu 10.04, with Apache 2.2.16 and mod_wsgi 3.2-2, and +2. Ubuntu 12.04, with Apache 2.2.22 and mod_wsgi 3.3-4. + +The same steps should work in other versions of Ubuntu as well. + +Note: + +* You may replace `appname` with your own project name. +* You may replace `code.py` with your own file name. +* `/var/www/webpy-app` found below refers to the path to the directory contains your code.py. +* `/var/www/webpy-app/code.py` is the full path to your python file. + +### Steps: + +1. Install mod_wsgi: + + sudo apt-get install libapache2-mod-wsgi + + This will install a `.so` module in Apache's **module directory**: + + /usr/lib/apache2/modules/mod_wsgi.so + + 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**… + + /etc/apache2/mods-available/wsgi.conf + /etc/apache2/mods-available/wsgi.load + …as well as in Apache's **enabled modules directory**: + + /etc/apache2/mods-enabled/wsgi.conf + /etc/apache2/mods-enabled/wsgi.load + +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: + + WSGIScriptAlias /appname /var/www/webpy-app/code.py/ + AddType text/html .py + + 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: + + Alias /appname/static /var/www/webpy-app/static/ + + After you have finished editing your website definition, you need to enable it (in case it is not already enabled). Do: + + sudo a2ensite my-website + +3. Finally, create a sample file `/var/www/webpy-app/code.py`: + + import web + + urls = ( + '/.*', 'hello', + ) + + class hello: + def GET(self): + return "Hello, world." + + application = web.application(urls, globals()).wsgifunc() + +4. Point your browser to 'http://your_server_name/appname' to verify whether it works for you. + +### Note: mod_wsgi + sessions + +If you use sessions with `mod_wsgi`, you should change you code like below: + + app = web.application(urls, globals()) + + curdir = os.path.dirname(__file__) + session = web.session.Session(app, web.session.DiskStore(os.path.join(curdir,'sessions')),) + + application = app.wsgifunc() + +### mod_wsgi performance: +For mod_wsgi performance, please refer to mod_wsgi wiki page: + + From f252d0f3483dcc67bd0dec0784dc3c196bf03e2e Mon Sep 17 00:00:00 2001 From: Marios Zindilis Date: Mon, 30 Jul 2012 01:24:47 +0300 Subject: [PATCH 2/2] Added new deployment case. --- cookbook/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cookbook/index.md b/cookbook/index.md index 15d35945..90d27850 100644 --- a/cookbook/index.md +++ b/cookbook/index.md @@ -85,7 +85,8 @@ _Other languages:_ [简体中文](/cookbook/index.zh-cn) | [日本語](/cookbook * [Fastcgi deployment through Apache](/cookbook/fastcgi-apache) * [CGI deployment through Apache](/cookbook/cgi-apache) * mod_python deployment through Apache (requested) -* [mod_wsgi deployment through Apache](/cookbook/mod_wsgi-apache ) +* [mod_wsgi deployment through Apache on Red Hat](/cookbook/mod_wsgi-apache) +* [mod_wsgi deployment through Apache on Ubuntu](/cookbook/mod_wsgi-apache-ubuntu) * [mod_wsgi deployment through Nginx](/cookbook/mod_wsgi-nginx ) * [Fastcgi deployment through Nginx](/cookbook/fastcgi-nginx) * [PyISAPIe deployment through IIS7/IIS6](/cookbook/iis7_iis6_windows_pyisapie)