Hosting an ASP.NET MVC2 website in Ubuntu using Mono

Summary: I’ve made my website Mono-ready and I’m going to explain what problems I ran into and how I fixed it.

I’m not going to keep quiet about it, when it comes to webservers I love Linux. Especially Ubuntu.

On the other hand I love Windows for everything else. And it has the single greatest IDE: Visual Studio 2010. Combining this with C# and ASP.NET MVC is pretty much pure awesome.

Now the best thing is that you can combine these two. Yes, you can actually host your .NET website on a Linux webserver. And that’s just what I did, thanks to the Mono project.

Some time ago (ages actually) I started a website with a friend of mine called CVgadget.com. CVgadget is “person search engine”, you enter a name and it tries to find as many results for that person possible. At that time I still made my websites in PHP. And to be truly honest this very old version is still in production. I converted it to a full fledged Zend Framework website once but that never made it to the public.

Time passed and at the company I was working as a part-timer at a began using ASP.NET MVC. I had used ASP.NET Web Forms before but I pretty much hated it, it might be great if you like to drag and drop your website together but a developer will see how messy it gets. It didn’t take long for me to fall in love with ASP.NET MVC and soon I was rewriting CVgadget. But then I found out how expensive Windows hosting actually is, luckily there is another choice: Mono.

Mono is “an open source, cross-platform, implementation of C# and the CLR that is binary compatible with Microsoft.NET”. And yes, you are able to host your website on a Linux box with Mono as well. Now, before you go wild and all you must know that the Mono implementation has some difference and your website probably isn’t going to work out of the box. For example: they didn’t implement EntityFramework. See the compatibility page. Good thing thing there is a worthy alternative for it: NHibernate, combine it with Fluent NHibernate and you are good to go. Oh well, that actually took some work but in the end I was able to properly convert my website and it seems to be working fine (it’s not publicly available yet).

This article is written for people who know their way around Linux, if you don’t you won’t find any pleasure in following this guide.

Setting up Ubuntu

Just install Ubuntu Server without any added features. Nathan Bridgewater has some excellent scripts to install Mono. I recommend installing version 2.8.1 of Mono as this seems to work best with NHibernate, don’t bother 2.8.2 (latest) it doesn’t work. Follow the instructions and you should be fine. This is all you need:

wget --no-check-certificate https://github.com/nathanb/iws-snippets/raw/master/mono-install-scripts/ubuntu/install_mono-2.8.1.sh
chmod 755 install_mono-2.8.1.sh
./install_mono-2.8.1.sh

Configuring Apache

By now mod_mono should be installed, we just have to enable it.

sudo ln -s /etc/apache2/mods-available/mod_mono.conf /etc/apache2/mods-enabled/mod_mono.conf

I removed the default site from Apache and generated a site configuration for mono using this tool. We will be using /srv/www/monotest/ as Document Root. Make sure that directory is owned by root:www-data.

sudo rm /etc/apache2/sites-enabled/*

After removing paste the generated config in a file called monotest in sites-available and enabled it.

sudo a2ensite monotest

Our first site

Create a default ASP.NET MVC 2 Web Application with Visual Studio, you know, the blueish one. A Unit test project is not necessarily. Publish your website somewhere local and upload the results to your Ubuntu server to /srv/www/monotest/.

Restart Apache

sudo service apache2 restart

Browse to the IP of your Ubuntu machine and hopefully you will be greeted by this:

That’s it for now. I’ll be back soon with an article about Fluent NHibernate and how to get the default example working on Ubuntu.

I hope you enjoyed this quick post, please let me know if everything worked for you and if I was clear enough. Do you need more explanation or are the steps clear enough?

Good luck with Mono!


  1. Godebald says:

    Mooi hoor Marv 😉

Leave a Reply

  • 2011: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
  • 2008: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
  • 2007: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec