Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 5 and Version 6 of ModPythonIntegration09


Ignore:
Timestamp:
02/08/06 16:23:20 (13 years ago)
Author:
alberto
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ModPythonIntegration09

    v5 v6  
    33The SVN version of TG uses cherrypy-2.2.0-beta which, AFAIK, is not compatible with the mpcp script described at the other modpy integration page. 
    44 
    5 I've managed to get it running using Robert Brewer's '''modpython_gateway.py'''. It has been tested on a Debian Sarge box, Apache 2.0.54 and a backported libapache2-mod-python2.4 package from Ubuntu (the package didn't install cleanly and some black drudgery had to be done to get it working by hand so I will not post it here yet, if there's some demand I might try to build a better backport). However, provided you can run your TG app with python2.3, you should be fine with Sarge's stock modpytyhon2.3. (I'm a big fan of 2.4's syntax sugar so I couldn't resist :) 
     5I've managed to get it running using Robert Brewer's '''modpython_gateway.py'''. It has been tested on a Debian Sarge box, Apache 2.0.54 (worker MPM) and a backported libapache2-mod-python2.4 package from Ubuntu (the package didn't install cleanly and some black drudgery had to be done in order to get it working by hand so I will not post it here yet, if there's some demand I might try to build a better backport).  
    66 
    7 Here is a quick recipe: 
     7However, provided you can run your TG app with python2.3, you should be fine with Sarge's stock modpytyhon2.3. (I'm a big fan of 2.4's syntax sugar so I couldn't resist :) 
     8 
     9== Quick recipe == 
    810 
    911 * Install wsigiref, {{{ sudo easy_install wsgiref }}} should get you going. 
    1012 * Download Robert's [http://projects.amor.org/misc/svn/modpython_gateway.py script] and place it inside wsgiref's package. 
    11  * You'll need to write a script to start your TG app as start-your.py will not work. It should be something like: 
     13 * You'll need to write a script to start your TG app as start-yourapp.py will '''not''' work. It should be something like: 
    1214 
    1315{{{ 
     
    1921import turbogears 
    2022 
     23turbogears.update_config(modulename="yourapp.config") 
    2124turbogears.update_config(configfile="/home/alberto/yourapp/prodcfg.py") 
    22 turbogears.update_config(modulename="yourapp.config") 
    2325 
    2426from yourapp.controllers import Root 
     
    3032 Make sure you don't make any reference to {{{sys.argv}}} (as modpython doesn't have a command line) and you use full paths (as Apache's working directory is /, like any well behaved unix daemon...). Don't forget to fix your paths and application name!. 
    3133 
    32  Place this script in your application's package (where controllers.py lives) 
     34 Place this script in your application's package (where controllers.py lives), let's say you call it {{{myapp_modpython.py}}}. 
    3335 
    3436 * Now you should {{{sudo python setup.py install }}} your app, you can get away by {{{sudo python setup.py develop }}} it. But then you should make your application's directory writable by your Apache user (normally www-data) which you should '''by no means''' do on a production box (if you can't guess why, then you should not be running a production box ;) 
    3537 
    36 '' More to come when I finish my dinner ;) '' 
     38 * Now you should configure your Apache virtual host, something like: 
     39{{{ 
     40NameVirtualHost 10.0.0.100:80 
     41<VirtualHost 10.0.0.100:80> 
     42    ServerName www.example.com 
     43    ServerAdmin webmaster@example.com 
     44    ServerSignature Off 
     45    AddDefaultCharset utf-8 
     46 
     47    <Location /> 
     48        SetHandler python-program 
     49        PythonHandler wsgiref.modpython_gateway::handler 
     50        PythonOption application cherrypy._cpwsgi::wsgiApp 
     51        PythonOption import myapp_modpython 
     52 
     53        # Switch it off when everything is working fine. 
     54        PythonDebug on 
     55 
     56        # This section can be skipped if you have no mod_deflate or don't want compression 
     57        # Recipe stolen somewhere around the httpd.apache.org realms. 
     58        <IfModule mod_deflate.c> 
     59             # Insert filter 
     60             SetOutputFilter DEFLATE 
     61 
     62             # Netscape 4.x has some problems... 
     63             BrowserMatch ^Mozilla/4 gzip-only-text/html 
     64 
     65             # Netscape 4.06-4.08 have some more problems 
     66             BrowserMatch ^Mozilla/4\.0[678] no-gzip 
     67 
     68             # MSIE masquerades as Netscape, but it is fine 
     69             # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
     70 
     71             # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48 
     72             # the above regex won't work. You can use the following 
     73             # workaround to get the desired effect: 
     74             BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html 
     75 
     76             # Don't compress images 
     77             SetEnvIfNoCase Request_URI \ 
     78             \.(?:gif|jpe?g|png|ico)$ no-gzip dont-vary 
     79 
     80             # Make sure proxies don't deliver the wrong content 
     81            <IfModule mod_headers.c> 
     82                Header append Vary User-Agent env=!dont-vary 
     83            </IfModule> 
     84        </IfModule> 
     85    </Location> 
     86 
     87    # For a little speed boost, you can let Apache serve (some of) your static files directly: 
     88    Alias /static /home/alberto/yourapp/static 
     89    Alias /favicon.ico /home/alberto/yourapp/static/images/favicon.ico 
     90    <Location /static> 
     91        SetHandler None 
     92    </Location> 
     93 
     94    <Directory /home/yourapp/static> 
     95        AllowOverride None 
     96        # FollowSymLinks is set for max. performance. For max security turn them off. 
     97        # However, if someone can make symlink in your server, this is your least motive for concern :) 
     98        Options -ExecCGI -Indexes -Multiviews +FollowSymLinks 
     99        Order allow,deny 
     100        allow from all 
     101    </Directory> 
     102</VirtualHost> 
     103}}} 
     104 
     105 Should get you going. Most of the configuration options don't add much to the understanding of this topic, The important stuff are the Python* directives. 
     106 
     107== Important things to consider == 
     108 
     109 * CherryPy's server logfile should be writable by www-data (if someone has a better solution please edit this page!, maybe dumping to stderr and let !PythonDebug catch it?) 
     110 
     111 * Use absolute paths or compute them at runtime, Apache lives at / 
     112 
     113 * Your app will be running under the Apache user (www-data on Debian), take this into account when setting permissions and ownership... 
     114 
     115Please, if you have any suggestions on how to imporove this set-up you should edit this page. If you have any suggestions on how to improve my english, do so as well :) 
    37116 
    38117