<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Werkzeug Documentation</title> <link rel="stylesheet" href="../_static/style.css" type="text/css"> <link rel="stylesheet" href="../_static/print.css" type="text/css" media="print"> <link rel="stylesheet" href="../_static/pygments.css" type="text/css"> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '0.6.1' }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/interface.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/werkzeug.js"></script> <link rel="contents" title="Global table of contents" href="../contents.html"> <link rel="index" title="Global index" href="../genindex.html"> <link rel="search" title="Search" href="../search.html"> <link rel="top" title="Werkzeug v0.6.1 documentation" href="../index.html"> <link rel="up" title="Application Deployment" href="index.html"> <link rel="next" title="FastCGI" href="fastcgi.html"> <link rel="prev" title="CGI" href="cgi.html"> </head> <body> <div class="page"> <div class="header"> <h1 class="heading"><a href="../index.html" title="back to the documentation overview"><span>Werkzeug</span></a></h1> </div> <ul class="navigation"> <li class="indexlink"><a href="../index.html">Overview</a></li> <li><a href="cgi.html">« CGI</a></li> <li class="active"><a href="#"><cite>mod_wsgi</cite> (Apache)</a></li> <li><a href="fastcgi.html">FastCGI »</a></li> </ul> <div class="body"> <div id="toc"> <h3>Table Of Contents</h3> <div class="inner"><ul> <li><a class="reference external" href="#"><cite>mod_wsgi</cite> (Apache)</a><ul> <li><a class="reference external" href="#installing-mod-wsgi">Installing <cite>mod_wsgi</cite></a></li> <li><a class="reference external" href="#creating-a-wsgi-file">Creating a <cite>.wsgi</cite> file</a></li> <li><a class="reference external" href="#configuring-apache">Configuring Apache</a></li> </ul> </li> </ul> </div> </div> <div class="section" id="mod-wsgi-apache"> <h1><cite>mod_wsgi</cite> (Apache)<a class="headerlink" href="#mod-wsgi-apache" title="Permalink to this headline">¶</a></h1> <p>If you are using the <a class="reference external" href="http://httpd.apache.org/">Apache</a> webserver you should consider using <a class="reference external" href="http://code.google.com/p/modwsgi/">mod_wsgi</a>.</p> <div class="section" id="installing-mod-wsgi"> <h2>Installing <cite>mod_wsgi</cite><a class="headerlink" href="#installing-mod-wsgi" title="Permalink to this headline">¶</a></h2> <p>If you don’t have <cite>mod_wsgi</cite> installed yet you have to either install it using a package manager or compile it yourself.</p> <p>The mod_wsgi <a class="reference external" href="http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide">installation instructions</a> cover installation instructions for source installations on UNIX systems.</p> <p>If you are using ubuntu / debian you can apt-get it and activate it as follows:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c"># apt-get install libapache2-mod-wsgi</span> </pre></div> </div> <p>On FreeBSD install <cite>mod_wsgi</cite> by compiling the <cite>www/mod_wsgi</cite> port or by using pkg_add:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c"># pkg_add -r mod_wsgi</span> </pre></div> </div> <p>If you are using pkgsrc you can install <cite>mod_wsgi</cite> by compiling the <cite>www/ap2-wsgi</cite> package.</p> <p>If you encounter segfaulting child processes after the first apache reload you can safely ignore them. Just restart the server.</p> </div> <div class="section" id="creating-a-wsgi-file"> <h2>Creating a <cite>.wsgi</cite> file<a class="headerlink" href="#creating-a-wsgi-file" title="Permalink to this headline">¶</a></h2> <p>To run your application you need a <cite>yourapplication.wsgi</cite> file. This file contains the code <cite>mod_wsgi</cite> is executing on startup to get the application object. The object called <cite>application</cite> in that file is then used as application.</p> <p>For most applications the following file should be sufficient:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">yourapplication</span> <span class="kn">import</span> <span class="n">make_app</span> <span class="n">application</span> <span class="o">=</span> <span class="n">make_app</span><span class="p">()</span> </pre></div> </div> <p>If you don’t have a factory function for application creation but a singleton instance you can directly import that one as <cite>application</cite>.</p> <p>Store that file somewhere where you will find it again (eg: <cite>/var/www/yourapplication</cite>) and make sure that <cite>yourapplication</cite> and all the libraries that are in use are on the python load path. If you don’t want to install it system wide consider using a <a class="reference external" href="http://pypi.python.org/pypi/virtualenv">virtual python</a> instance.</p> </div> <div class="section" id="configuring-apache"> <h2>Configuring Apache<a class="headerlink" href="#configuring-apache" title="Permalink to this headline">¶</a></h2> <p>The last thing you have to do is to create an Apache configuration file for your application. In this example we are telling <cite>mod_wsgi</cite> to execute the application under a different user for security reasons:</p> <div class="highlight-apache"><div class="highlight"><pre><span class="nt"><VirtualHost</span> <span class="s">*</span><span class="nt">></span> <span class="nb">ServerName</span> example.com <span class="nb">WSGIDaemonProcess</span> yourapplication <span class="k">user</span>=user1 <span class="k">group</span>=group1 processes=2 threads=5 <span class="nb">WSGIScriptAlias</span> / <span class="sx">/var/www/yourapplication/yourapplication.wsgi</span> <span class="nt"><Directory</span> <span class="s">/var/www/yourapplication</span><span class="nt">></span> <span class="nb">WSGIProcessGroup</span> yourapplication <span class="nb">WSGIApplicationGroup</span> %{GLOBAL} <span class="nb">Order</span> deny,allow <span class="nb">Allow</span> from <span class="k">all</span> <span class="nt"></Directory></span> <span class="nt"></VirtualHost></span> </pre></div> </div> <p>For more information consult the <a class="reference external" href="http://code.google.com/p/modwsgi/wiki/">mod_wsgi wiki</a>.</p> </div> </div> <div style="clear: both"></div> </div> <div class="footer"> © Copyright 2008 by the <a href="http://pocoo.org/">Pocoo Team</a>, documentation generated by <a href="http://sphinx.pocoo.org/">Sphinx</a> </div> </div> </body> </html>