web.py and wscgi

After tinkering, you might want to make your app a bit more production ready and/or make it start when the system boots.

Although it is very handy to have it run on a local port, using WSCGI and apache makes it straightforward to do just that. There are a few gotchas though:

(this is on ubuntu 16.04, but it should apply to most OSes)

apt-get install libapache2-mod-wsgi

in /etc/apache2/sites-available:
vi subdomain.domain.com.conf

<VirtualHost *:80>
        ServerAdmin you@whatnot.com
        WSGIScriptAlias / /var/www/yourapp/app.py/
        AddType text/html .py
        ServerName subdomain.domain.com

        ErrorLog ${APACHE_LOG_DIR}/error_myapp.log
        CustomLog ${APACHE_LOG_DIR}/access_myapp.log combined
</VirtualHost>

then a2ensite subdomain.domain.com
and reload apache.

in python:

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

please note that application must appear exactly as above, you can't name it anything else.

since apache does not allow you to import MyModule directly, you need to add it like this (assuming it's in the same folder as your app)

import os
import sys
CURDIR = os.path.dirname(__file__)
sys.path.append(CURDIR)
import MyModule

--- also please see http://webpy.org/cookbook/mod_wsgi-apache-ubuntu