22 Jan 2009, 8:10 p.m.

More Mono: mod_mono and Apache

In Getting Started with Mono on Linux I mentioned that my next plan was to get Mono integrated with Apache HTTPD by way of mod_mono.

This turned out to be a bit of a wrestling match. The process itself is remarkably simple, but the poor - or at least outdated - documentation combined with a few minor teething problems made it all much harder than it could have been.

Interestingly, I get the impression that there aren't a lot of people out there doing this stuff. The relative fruitfulness of Google searches for problems one comes up against when learning a technology tends to be a good barometer of that technology's popularity, and in most cases here, searching revealed very little of any help.

Nevertheless, let's crack on with getting mod_mono installed.

Getting mod_mono

The first challenge here is playing "hunt the source code". As previously noted, Mono is offically supported on only a limited number of platforms, Fedora Linux not being among them. Furthermore, the Mono site's promises of a mod_mono download come to nothing, leading the user to click aimlesly around hoping to stumble upon it.

Fortunately, some creative Google searching led to Novell's mirror of mod_mono releases, which was a relief.

Installing mod_mono

Once you've found the code, installing mod_mono is a fairly typical configure/make/make install cycle.

Note that Mono itself and XSP are prerequisites for installing mod_mono, so if you don't have those yet it would be worth giving the previous post the once over.

Here are the commands I ran to build and install mod_mono:

[root@vps02 src]# tar -jxvf mod_mono-1.9.tar.bz2
[root@vps02 src]# ln -s mod_mono-1.9 mod_mono
[root@vps02 src]# cd !$
[root@vps02 mod_mono]# ./configure --prefix=/path/to/mono/ \
    --with-apxs=/path/to/httpd/bin/apxs
[root@vps02 mod_mono]# make
[root@vps02 mod_mono]# make install

The only point of any note is that you need to specify the path to apxs if you wish to build mod_mono as a DSO, which makes sense. Incidentally, if Apache is already running, I tend to stop it prior to make installing anything that touches it, as I've had it hang at that point on several occasions.

The install procedure will have placed mod_mono.so into /path/to/httpd/modules/, and mod_mono.conf into /path/to/httpd/conf/. The latter file neatly contains all the Apache configuration information you'll need. This includes the LoadModule directive to load mod_mono in the first place, plus directives to associate various appropriate file suffixes (.aspx, .asmx etc) with mod_mono, and also to specify a handful of new DirectoryIndex candidates.

The next thing to do is find somewhere to host your files, and I created a virtual host specifically for this purpose. To add mod_mono to your Apache HTTPD configuration is then as simple as adding Include "conf/mod_mono.conf" to the relevant VirtualHost in the usual Apache config file.

To get things up and running, it might be worth copying the contents of XSP's test folder - /path/to/mono/lib/xsp/test/ - into the root from which the host is serving. That's exactly what I did, and you can see the results here (page removed now).

That's pretty much all there is to it, but there are, of course, more advanced configuration options available, an overview of which can be found here.

As mentioned at the beginning of this post, the process didn't actually go as smoothly as I might have just implied, so I'll quickly highlight a couple of things that went wrong and how I got around them.

Troubleshooting 1

I started by following the instructions on the Mono site here, which didn't come close to working. Firstly, there is no libmod_mono.so, although there may have been at one point. Secondly, once that's corrected, Apache will not restart, instead generating this cryptic error message:

[Thu Jan 22 10:43:51 2009] [crit] (13)Permission denied: Failed to attach to existing dashboard, and removing dashboard file '/tmp/mod_mono_dashboard_XXGLOBAL_1' failed (Operation not permitted). Further action impossible.

I never got to the bottom of this, but I did subsequently find the instructions linked to previously, and decided to go the much simpler "Autohosting" route, as described above, and managed to make more progress that way.

Troubleshooting 2

Once I did get mod_mono installed, and associated with the correct files, I found I was generating nothing but "500 Internal Server Errors". There was nothing in the virtual host's error logs, which led to some frustration. Curiously enough though, messages were being logged to the default "localhost" error log. They were as follows:


mod_mono and xsp have different versions. Expected '8', got 9
System.InvalidOperationException: mod_mono and xsp have different versions. Expected '8', got 9
  at Mono.WebServer.ModMonoRequest.GetInitialData () [0x00000]
  at Mono.WebServer.ModMonoRequest..ctor (System.Net.Sockets.NetworkStream ns) [0x00000]
  at Mono.WebServer.RequestReader..ctor (System.Net.Sockets.NetworkStream ns) [0x00000]
  at Mono.WebServer.ModMonoWorker.InnerRun (System.Object state) [0x00000]
  at Mono.WebServer.ModMonoWorker.Run (System.Object state) [0x00000]

The version 8 versus version 9 issue is slightly misleading, but the crux of the matter is that your Mono and mod_mono versions do in fact need to be in sync. I had naively just grabbed the latest version of mod_mono that could be found (2.2). Removing it and installing mod_mono 1.9 - also from the Novell site - solved the problem.

Posted by Simon in Programming