There is a video at the end of this post walking through it.
Once you get it figured out its easy. I always like to try to get my asp.net apps to run on mono so that I can say they can. The itch to do that with MVC 2 came back around a week ago, and I thought like every other time it was going to be simple. After some good googling I came up short, except to learn that MVC 2 is in the core of 2.7 and in the core of 2.8
preview. (Updated Post Since Official Release of 2.8)
I am a person that has never had luck installing mono from source, until today. So this was an adventure that took me probably 8 hours to figure out from start to end, and something I can redo now in about 30 minutes, including compile time.
I am going to list all my steps and why so you can know what is going on too. These are the steps on a complete fresh install of Ubuntu 10.04 Server, after updating it.
Step 1: Dependencies
apt-get install build-essential bison gettext pkg-config autoconf libtool automake
build-essential, bison, and gettext are required for the actual compilation of the source code. Fortunately, if you don’t install one of them it will complain at you and tell you what you don’t have.
pkg-config, autoconf, libtool, and automake are required for mono itself and running the configuration even before compilation. If you don’t do this step it too will complain at you.
Step 2: Compile and Install Mono from Source
tar -xjvf mono-2.8.tar.bz2
The above is pretty basic and easy to understand. Just note the –prefix=/usr there so it installs all the mono apps to /usr/bin. I made the mistake of doing –prefix=/usr/bin/ and it installed everything /usr/bin/bin. It was not pretty trying to fix the problem.
Step 3: Compile and Install XSP Server
tar -xjvf xsp-2.8.tar.bz2
This creates several of the things you need to run your ASP.NET applications. Of note for later it creates the application mod-mono-server4 which is what you will use to run your MVC 2 application on the .NET 4.0 framework.
Step 4: Install Apache
apt-get install apache2 apache2-dev
Now it is time to install apache, if it isn’t installed already. Also be sure to install the apache2-dev package since mod_mono needs it.
Step 5: Compile and Install mod_mono
tar -xjvf mod_mono-2.8.tar.bz2
Just like above this is pretty normal. Specifically what this does is it creates a config file for apache and the apache module. It puts the mod-mono.so module in the correct place, but not the apache config file.
Step 6: Fix mod_mono.conf File Location
mv /etc/apache2/mod_mono.conf /etc/apache2/mods-available/
This will put the file in the correct location. At this point we should be able to do ‘a2enmod mod_mono’, but it doesn’t seem to work. I didn’t move this to the mods-enabled folder because I wanted to keep with convention.
Step 7: Setup Symlink to Enable Site mod_mono
ln -s /etc/apache2/mods-available/mod_mono.conf /etc/apache2/mods-enabled/mod_mono.conf
a2enmod creates a symlink to files from /etc/apache2/mods-available/ to /etc/apache2/mods-enabled. This is a good convention to hold on to so the above line does just that.
Step 8: Letting Apache take Hold of Changes
Everything “should” load up normally at this point. If not read through the output and see if you can’t figure out what isn’t correct.
Step 9: Setting Up Virtual Host
This is a normal vhost file you would use anywhere with ASP.NET. The only difference for the ability to render MVC 1 and 2 is the MonoServerPath line. The end of it should point to mod-mono-server4 instead of 1 or 2*. If you don’t change this you will probably get a “targetFramework” error with your web.config file.
Just drop your MVC 2 app in “/srv/www/net.example.net/public_html/” and move on to the next step.
*.NET 1.1 support has been dropped with this latest release so mod-mono-server1 probably wont be there.
Step 10: Getting it all Working
Now is time to reload the apache vhost configurations. This assumes you have a virtualhost file loaded and ready to go. For the first install of mono I like to just restart apache.
At this point you should be able to browse your MVC 2.0 app, from the URL you set. It was quite a thrill to get it working the first time. For a test I made an MVC 2.0 app in Visual Studio 2010 built it. Then copied all the files over the server and it worked out of the box, once the above 10 steps were done.
I hope this helps other people and it works for them. It was a lot of fun and I learned a lot getting this working. If you have any questions please feel free to ask.