Hosting an ASP.NET MVC2 website in Ubuntu using Mono

No Comments »

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!


Mono 2.8.2 and Fluent NHibernate error

No Comments »

The latest Mono and Fluent NHibernate will give you a nice error. If you got the following error install Mono 2.8.1

Compilation Error Description: Error compiling a resource required to service this request. Review your source file and modify it to fix this error. Compiler Error Message: CS0011: Could not load type ‘FluentNHibernate.Mapping.ComponentPartBase`2[T,FluentNHibernate.Mapping.ComponentMap`1[T]]’ from assembly ‘FluentNHibernate, Version=1.1.0.685, Culture=neutral, PublicKeyToken=8aa435e3cb308880′. ~/Global.asax


CentOS cheat sheet

No Comments »

In the past few days I’ve set up a CentOS dedicated server. I’ve always been working with Ubuntu Server or Debian before. Both distros have a lot in common but some things you just gotta know. Here’s a list of what I think is important for setting up a server. This is also a quick overview for me.

Installing a package with Yum (apt-get alike)
yum install <packagename> (use -y to say yes to all questions)

Boot service at startup
chkconfig –add <name> (to add service to list)
chkconfig –del <name> (to remove service from list)
chkconfig on (to start with default levels)
chkconfig –level 234 <name> on (to start with levels 2,3 & 4)
chkconfig –list (to see status of all)

Restart a service
service <name> restart

Quick LAMP setup
yum install httpd openssl php mysql php-mysql mysql-server php-gd

Apache directory
/etc/httpd/

more to come…

P.S. I can recommend everyone to use a panel such as DirectAdmin instead of installing and setting up it all by yourself. If your hosting gives a option to use it for EUR 5 more/month DO IT. It will save you so much time!

Some nice links:

Building a secure Linux web server (LAMP) Guide by Ray Heffer

CentOS 5.1 Server Setup: LAMP, Email, DNS, FTP, ISPConfig (a.k.a. The Perfect Server)


RawClient simple java http client

No Comments »

With this really simple client you’re able to experiment with HTTP headers. Go try it out!

License: MIT

Includes: source

Download


SMTP MailClient including SMTP Server emulator

No Comments »

This project was made by a classmate

This is a small schoolproject. It’s a smtp client including a smtp server emulator. You can dowload it here. I’ve include the source and javadoc with it. Feel free to use it, but give the site¬†the credits for this creation¬†:-)

Good luck and have fun ^^

Download

~Ewout


Webservert: simple Java webserver

No Comments »

Webservert is a really simple Java web server. It is intended as a school project. I’ve published it here for learning purposes.

License: MIT

Includes: source, binary, javadoc

Download


  • 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