x
Search Posts:
BLOG POST #117 SHOW ALL

Apache2 + mod_wsgi + web.py on Debian 6 server

root@machine~$ apt-get install libapache2-mod-wsgi
root@machine~$ a2enmod wsgi

root@machine~$ mkdir /var/www/webpytest
root@machine~$ mkdir /var/www/webpytest/py
root@machine~$ mkdir /var/www/webpytest/http
root@machine~$ mkdir /var/www/webpytest/logs
root@machine~$ mkdir /var/www/webpytest/static

root@machine~$ vim /var/www/webpytest/py/code.py
###
  import web

  urls = (
  '/.*', 'hello',
  )

  class hello:
    def GET(self):
      return "Hello, world."

application = web.application(urls, globals()).wsgifunc()
###


root@machine~$ chown -R user:www-data /var/www/webpytest
root@machine~$ chmod -R 775 /var/www/webpytest

root@machine~$ vim /etc/apache2/sites/available/webpytest
###
<VirtualHost *:80>
    ServerName webpytest.local
    DocumentRoot /var/www/webpytest/http
    
    ErrorLog /var/www/webpytest/logs/error.log
    CustomLog /var/www/webpytest/logs/access.log combined
    
    WSGIScriptAlias / /var/www/webpytest/py/code.py
    
    Alias /static /var/www/webpytest/static
    
    AddType text/html .py
    
    <Directory />
        Order Allow,Deny
        Allow From All
        Options -Indexes
    </Directory>
    
    <Directory /var/www/webpytest/static>
        # directives to effect the static directory
        Options +Indexes
    </Directory>
</VirtualHost>
###

root@machine~$ a2ensite webpytest
root@machine~$ service apache2 reload

#########
Sources:
http://webpy.org/cookbook/mod_wsgi-apache
http://webpy.org/cookbook/staticfiles
https://library.linode.com/web-servers/apache/mod-wsgi/debian-6-squeeze