Thursday, October 25, 2012

web2py and apache2/mod_python

Finally got it to work!

web2py is an open source Python based web application framework. I had the fun of setting one up on a SuSE ELS 11.1 server. Not wanting to go outside the distribution to alert the server administrative team, I stayed with what are available in the repository, which does not have the WSGI module. So I went with the Python module for Apache.

There is a file named modpythonhandler.py in the top folder of web2py installation, with sample configuration in it. But following that I get an "invalid request" message from accessing web2py. I searched on Google for setting up web2py with mod_python, but it still took me some time and trials to get it right. So here is what I have learned from this experience.

One thing is to setup access to the static files (CSS, JavaScripts, etc.):
AliasMatch ^/([^/]+)/static/(.+)$ /path/to/web2py/applications/$1/static/$2
That turns request for welcome/static/js/jquery.js to the actual path to that file, which is usually in the applications subfolder.

Next, setup the handler for web2py -- All client requests pass through the handler, except for the static files:


SetHandler python-program PythonHandler web2py_modpython PythonPath "sys.path+['/path/to/web2py']"
AllowOverride FileInfo Options -Indexes FollowSymLinks Order Allow,Deny Allow from all
Next, the static files:

SetHandler None Options -Indexes FollowSymLinks ExpiresActive On ExpiresDefault "access plus 1 hour" Order Allow,Deny Allow from all
Files in all the static/ subfolders should be handled by Apache directly.

The content of the web2py_modpython.py file (the Python handler):
from mod_python import apacheimport modpythonhandler
def handler(req):    req.subprocess_env['PATH_INFO'] = '/welcome/default/index'    return modpythonhandler.handler(req)
The end.

Saturday, October 20, 2012

VPN in Ubuntu and Upgrading to 12.10, Quantal Quetzal

The latest release of Ubuntu hit the news a couple of days ago. I have been hesitant upgrading for some time as I have become less enthusiastic about new operating system features since moving away from system level development.

My experiences following Ubuntu has been that, every time a new release comes out, some functions are broken. Over time, bugs get reported, updates released and broken functions repaired. It has been a great OS for years, although Unity has not been my favorite. Between Gnome and KDE, I have always liked Gnome better, so I have stayed with Ubuntu, using it on my desktop, my netbook, and home server.

After reading about the 12.10 release for a few days, I decided to upgrade my desktop. The upgrade went pretty smooth besides taking a while. I went the command line route as that was easier for me.

Before I started the upgrade process, I had to enable the upgrade to a non-long-term-support (LTS) release -- Ubuntu does 2 release every year, one in April and one in October, which is where the release numbers like 10.04 and 12.10 come from. The latest release, 12.10, means it is released in October 2012. I forgot the file containing that option, so I started the System Tools » Administration » Update Manager, went to Settings and change the Notify me of a new Ubuntu version option from For long-term support versions to For any new version.

Then in a terminal window, I did a do-release-upgrade. That's pretty much it -- all I had to do after than was answering a few questions about new configuration files -- Since I haven't done much customization, I only had to answer y.

The upgrade process kept all my personalizations, including my choice of Gnome 3 and background images, etc.

But then almost immediately after reboot into 12.10, I noticed something not working: My VPN to work. It is a Cisco AnyConnect setup. The Network Manager isn't much help -- it just says connection failed. In syslog, this one message looks quite suspicious: Failed to open tun device: Permission denied -- I checked /dev/net/tun, I should already have read and write access to it per group permissions. Only by granting world read/write access to the tun device seems to make VPN work -- That seems rather strange. But that's a story for another day.