"Invalid command WSGIScriptAlias" on Debian Lenny

When using Python applications with Apache2 and mod_wsgi, Debian sometime acts as if wsgi is not installed (althou it is).

Once upon a time, on my Debian server.

computer:~# /etc/init.d/apache2 restart                                                                                                    
Restarting web server: apache2We failed to correctly shutdown apache, so we're now killing all running apache processes. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now! (warning).                                                                                                                      
 ... waiting .Syntax error on line 17 of /etc/apache2/sites-enabled/cthulhubot-rlyeh-mod-wsgi:
Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the server configuration
 failed!

Long story short:

computer:~# dpkg --purge --force-all libapache2-mod-wsgi
computer:~# apt-get install libapache2-mod-wsgi

Diagnostic

After initial fail, could it be we have not WSGI installed?

computer:~# dpkg -l | grep wsgi
ii  libapache2-mod-wsgi                    2.5-1~lenny1             Python WSGI adapter module for Apache

Nope, it is. Maybe just not enabled?

cnt-cthulhubot-tester:~# a2enmod wsgi
ERROR: Module wsgi does not exist!

Wait. What?

computer:~# ls /etc/apache2/mods-available/ | grep wsgi         
wsgi.conf

Now, if You know how mods are structured, there is the problem. .conf file configure loaded module (if You will open it, You'll see <IfModule mod_wsgi.c> directive. To load given module, .load file has to be present (and should be; go check list of files from representative source).

So, now You know Your installation is broken. Reinstall as mentioned above and You should be fine.

Of course, You should dig deeper on why the hell could this happen. In my case, it was bad dependency handling in some of our custom packages, causing mod-wsgi to be „fakely“ installed after some package management mumbo jumbo (configuration files are preserved even when package itself is not installed).

Published on June 9, 2010 under admin beginners english howto linux