Skip to content
Myr

Reordered deployment docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 5310fc3 · Browse files · 1 file+127 added−126 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+127 added−126 removed

  • other:+127 added−126 removed

1 file+127 added−126 removed

modified:docs/deploying.rst+127 added-126 removed
9 unmodified lines
10how to use a WSGI app with it. Just remember that your application object11is the actual WSGI application.121314mod_wsgi (Apache)15-----------------1617If you are using the `Apache`_ webserver you should consider using `mod_wsgi`_.1819.. _Apache: http://httpd.apache.org/2021Installing `mod_wsgi`22`````````````````````2324If you don't have `mod_wsgi` installed yet you have to either install it using25a package manager or compile it yourself.2627The mod_wsgi `installation instructions`_ cover installation instructions for28source installations on UNIX systems.2930If you are using ubuntu / debian you can apt-get it and activate it as follows::3132 # apt-get install libapache2-mod-wsgi3334On FreeBSD install `mod_wsgi` by compiling the `www/mod_wsgi` port or by using35pkg_add::3637 # pkg_add -r mod_wsgi3839If you are using pkgsrc you can install `mod_wsgi` by compiling the40`www/ap2-wsgi` package.4142If you encounter segfaulting child processes after the first apache reload you43can safely ignore them. Just restart the server.4445Creating a `.wsgi` file46```````````````````````4748To run your application you need a `yourapplication.wsgi` file. This file49contains the code `mod_wsgi` is executing on startup to get the application50object. The object called `application` in that file is then used as51application.5253For most applications the following file should be sufficient::5455 from yourapplication import app as application5657If you don't have a factory function for application creation but a singleton58instance you can directly import that one as `application`.5960Store that file somewhere where you will find it again (eg:61`/var/www/yourapplication`) and make sure that `yourapplication` and all62the libraries that are in use are on the python load path. If you don't63want to install it system wide consider using a `virtual python`_ instance.6465Configuring Apache66``````````````````6768The last thing you have to do is to create an Apache configuration file for69your application. In this example we are telling `mod_wsgi` to execute the70application under a different user for security reasons:7172.. sourcecode:: apache7374 <VirtualHost *>75 ServerName example.com7677 WSGIDaemonProcess yourapplication user=user1 group=group1 threads=578 WSGIScriptAlias / /var/www/yourapplication/yourapplication.wsgi7980 <Directory /var/www/yourapplication>81 WSGIProcessGroup yourapplication82 WSGIApplicationGroup %{GLOBAL}83 Order deny,allow84 Allow from all85 </Directory>86 </VirtualHost>8788For more information consult the `mod_wsgi wiki`_.8990.. _mod_wsgi: http://code.google.com/p/modwsgi/91.. _installation instructions: http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide92.. _virtual python: http://pypi.python.org/pypi/virtualenv93.. _mod_wsgi wiki: http://code.google.com/p/modwsgi/wiki/949596CGI97---9899If all other deployment methods do not work, CGI will work for sure. CGI100is supported by all major servers but usually has a less-than-optimal101performance.102103This is also the way you can use a Flask application on Google's104`AppEngine`_, there however the execution does happen in a CGI-like105environment. The application's performance is unaffected because of that.106107.. _AppEngine: http://code.google.com/appengine/108109Creating a `.cgi` file110``````````````````````111112First you need to create the CGI application file. Let's call it113`yourapplication.cgi`::114115 #!/usr/bin/python116 from wsgiref.handlers import CGIHandler117 from yourapplication import app118119 CGIHandler().run(app)120121If you're running Python 2.4 you will need the :mod:`wsgiref` package. Python1222.5 and higher ship this as part of the standard library.123124Server Setup125````````````126127Usually there are two ways to configure the server. Either just copy the128`.cgi` into a `cgi-bin` (and use `mod_rerwite` or something similar to129rewrite the URL) or let the server point to the file directly.130131In Apache for example you can put a like like this into the config:132133.. sourcecode:: apache134135 ScriptName /app /path/to/the/application.cgi136137For more information consult the documentation of your webserver.138139140141FastCGI142-------143144A very popular deployment setup on servers like `lighttpd`_ and `nginx`_
122 unmodified lines
267.. _nginx: http://nginx.net/268.. _flup: http://trac.saddi.com/flup269270144mod_wsgi (Apache)145-----------------271147If you are using the `Apache`_ webserver you should consider using `mod_wsgi`_.148149.. _Apache: http://httpd.apache.org/150151Installing `mod_wsgi`152`````````````````````153154If you don't have `mod_wsgi` installed yet you have to either install it using155a package manager or compile it yourself.156157The mod_wsgi `installation instructions`_ cover installation instructions for158source installations on UNIX systems.159160If you are using ubuntu / debian you can apt-get it and activate it as follows::161162 # apt-get install libapache2-mod-wsgi163164On FreeBSD install `mod_wsgi` by compiling the `www/mod_wsgi` port or by using165pkg_add::166167 # pkg_add -r mod_wsgi168169If you are using pkgsrc you can install `mod_wsgi` by compiling the170`www/ap2-wsgi` package.171172If you encounter segfaulting child processes after the first apache reload you173can safely ignore them. Just restart the server.174175Creating a `.wsgi` file176```````````````````````177178To run your application you need a `yourapplication.wsgi` file. This file179contains the code `mod_wsgi` is executing on startup to get the application180object. The object called `application` in that file is then used as181application.182183For most applications the following file should be sufficient::184185 from yourapplication import app as application186187If you don't have a factory function for application creation but a singleton188instance you can directly import that one as `application`.189190Store that file somewhere where you will find it again (eg:191`/var/www/yourapplication`) and make sure that `yourapplication` and all192the libraries that are in use are on the python load path. If you don't193want to install it system wide consider using a `virtual python`_ instance.194195Configuring Apache196``````````````````197198The last thing you have to do is to create an Apache configuration file for199your application. In this example we are telling `mod_wsgi` to execute the200application under a different user for security reasons:201202.. sourcecode:: apache203204 <VirtualHost *>205 ServerName example.com206207 WSGIDaemonProcess yourapplication user=user1 group=group1 threads=5208 WSGIScriptAlias / /var/www/yourapplication/yourapplication.wsgi209210 <Directory /var/www/yourapplication>211 WSGIProcessGroup yourapplication212 WSGIApplicationGroup %{GLOBAL}213 Order deny,allow214 Allow from all215 </Directory>216 </VirtualHost>217218For more information consult the `mod_wsgi wiki`_.219220.. _mod_wsgi: http://code.google.com/p/modwsgi/221.. _installation instructions: http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide222.. _virtual python: http://pypi.python.org/pypi/virtualenv223.. _mod_wsgi wiki: http://code.google.com/p/modwsgi/wiki/224225226272Tornado273--------274275`Tornado`_ is an open source version of the scalable, non-blocking web server and tools that power `FriendFeed`_.
28 unmodified lines
304305.. _Gevent: http://www.gevent.org/306.. _greenlet: http://codespeak.net/py/0.9.2/greenlet.html307.. _libevent: http://monkey.org/~provos/libevent/263264CGI265---266267If all other deployment methods do not work, CGI will work for sure. CGI268is supported by all major browsers but usually has a less-than-optimal269performance.270271This is also the way you can use a Flask application on Google's272`AppEngine`_, there however the execution does happen in a CGI-like273environment. The application's performance is unaffected because of that.274275.. _AppEngine: http://code.google.com/appengine/276277Creating a `.cgi` file278``````````````````````279280First you need to create the CGI application file. Let's call it281`yourapplication.cgi`::282283 #!/usr/bin/python284 from wsgiref.handlers import CGIHandler285 from yourapplication import app286287 CGIHandler().run(app)288289If you're running Python 2.4 you will need the :mod:`wsgiref` package. Python2902.5 and higher ship this as part of the standard library.291292Server Setup293````````````294295Usually there are two ways to configure the server. Either just copy the296`.cgi` into a `cgi-bin` (and use `mod_rerwite` or something similar to297rewrite the URL) or let the server point to the file directly.298299In Apache for example you can put a like like this into the config:300301.. sourcecode:: apache302303 ScriptName /app /path/to/the/application.cgi304305For more information consult the documentation of your webserver.306