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.

Comments

This entry was posted on Thursday, October 5th, 2006 at 11:14 pm and is filed under General, Linux, Tinkering, Web Apps, Windows. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

3 Comments so far

  1. dor on June 4, 2007 7:16 am

    Thank you, it helped me a lot!

  2. Joe on August 21, 2008 7:44 am

    I’m an asp.net web developer. I would love to get Mono running on Ubuntu. I’ve tried serveral times in the past to do this but within 10 minutes of getting the OS installed I end up troubleshooting either the mono updates or mysql. The biggest difference between Linux and Windows is the amount of information (and its correctness) on the net. Linux needs more people like you that are willing to write more help articles. I keep dropping Linux because there just isn’t enough information on its problems. Keep trying guys, one day it may pay off.

  3. Zachary Burns on August 26, 2008 12:47 pm

    For those of you having an issue with Ubuntu Server 8.04.1 LTS and Mod-Mono there is an error in the file
    /etc/mono-server2/mono-server2-hosts.conf

    Change the line that says

    MonoServerPath default /usr/lib/mono/2.0/mod-mono-server2.exe

    to be:

    MonoServerPath default /usr/bin/mod-mono-server2

Name (required)
Email (required)
Website
Share your wisdom
  • Recent Comments