Dogs and cats living together… it'll be anarchy!

I was curious how hard it would be to get to get a C# development box running on Linux – for web application development that is. You may or may not know about the mono project (a unixy port of the .net and complier runtime among other things), but there is also a mod_mono apache module that you can use to run .net web applications.

This quick howto is for playing around only. I got it to work, but I have a feeling this is not the optimal way to get it to work. Also, the “code behind” style doesn't seem to work doing it this way – but again it could be the way it's setup.

This will follow along pretty closely with the Howto Setup Python one. Here we go.

Most of this will require root so you'll want to just switch now:

rob@server:$ sudo bash

Grab mono and the compiler if it's not there already:

root@server:# apt-get install mono mono-gmcs

Now, here is where it gets a bit funky. My apt-get sources list does not have the apache modules for mod_mono. mod_mono however exists for Debain so it should be out there, but it wasn't in my default source list. Check to see if your sources list has the needed stuff by doing:

root@server:# apt-cache dump | grep mono-apache-server2

If that comes back with nothing, you'll need to update your /etc/apt/sources.list file. Follow this then continue.

Now we need to grab the mod_mono stuff. Install it using:

root@server:# sudo apt-get install mono-apache-server2 libapache2-mod-mono

Everything should now be installed. On to configuration.

Create a symbolic link in the mods-enabled directory:

root@server:# cd /etc/apache2/mods-enabled/
root@server:/etc/apache2/mods-enabled# ln -s ../mods-available/mod_mono.load mod_mono.load

I also did a symbolic link for the config file (this may not be needed)

root@server:/etc/apache2/mods-enabled# ln -s ../mods-available/mod_mono.conf mod_mono.conf

Now you might try restarting apache (/etc/init.d/apache restart) at this point and check to see if you get the following error:

 * Starting apache 2.0 web server...
apache2: could not open document config file /etc/mono-server/mono-server-hosts.conf
...fail!

I did. If you do as well, you'll find that that file indeed doesn't exist, but one called /etc/mono-server2/mono-server-hosts2.conf does. It seems there is a mix between version 1 and version 2. The simple fix, and the one I did, was just make a simlink:

root@server:# cd /etc/
root@server:/etc# ln -s mono-server2 mono-server
root@server:/etc# cd mono-server
root@server:/etc/mono-server# ln -s mono-server2-hosts.conf mono-server-hosts.conf

Once you got that all squared away (or fixed properly), you can update the apache configuration file. I, again, am just using the /etc/apache2/conf.d/alias file, but you could do something like this for the whole apache server if you would like:

MonoApplications "/mono:/home/rob/mono"
Alias /mono "/home/rob/mono"
<Directory /home/rob/mono>
SetHandler mono
AddHandler mod_mono .aspx .ascx .asax .ashx .config .cs .asmx
</Directory>

And now… the test page. Go into the directory you have setup to handle .net stuff (/home/rob/mono in the example above), and create a test page – say Default.aspx – with something like:

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
protected void Page_Load(Object sender, EventArgs e)
{
Label1.Text = "Hello World!";
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Hello World</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

Probably not the most optimal setup, but I couldn't find much on how to do it. If you are trying to do this I hope this at least got you off to a start. Most of this was pieced together from the following sites: http://beans.seartipy.com/
http://www.fedoraforum.org
http://ubuntuguide.org/
http://www.odetocode.com/

It definitely felt weird to ssh into a Linux box and write some C# code with Emacs – but cool non-the-less.