Installing MVC3 on Mono with Ubuntu
April 22, 2013
I managed to get the wiki engine I spend a lot of more spare time writing, Roadkill working on Ubuntu with Mono this weekend. Unfortunately for me, a lot of the documentation is patchy which meant it took a few hours to get it up and running by scouring Stackoverflow, blogs and news groups. It is infact very simple to get MVC3 working with Apache on Linux, provided you have the right Apache config settings and are willing to add a few hacks into your code to cater for the gaps (NotImplementedExceptions) in the Mono framework.
Below are two snippets for getting Mono and MVC3 going with Ubuntu. The majority of the credit goes to:
- http://www.toptensoftware.com/Articles/6/Setting-up-a-Ubuntu-Apache-MySQL-Mono-ASP-NET-MVC-2-Development-Server
- http://devblog.rayonnant.net/2012/11/mvc3-working-in-mono-ubuntu-1210.html
Copy the second snippet into /var/www/default.txt and save the first snippet as “install.sh” into your user directory, running it using “sudo sh install.sh”. The full Roadkill bash script can be found here. I started making EC2 AMIs for the installation, and then found a few issues that made me eventually abandon my dreams of a cheap $5 Roadkill Ubuntu server, as it would be a lot of effort maintaining both Windows and Mono tests for Roadkill.
Don’t take that as criticism of Mono + MVC3 though - Roadkill does a lot with the framework that most apps wouldn’t. If you are running data-driven MVC apps, then using a database like MongoDB would work very well with Mono on Ubuntu.
sudo apt-get -y update | |
# Install Apache, Mono and mod_mono. | |
# mod_mono may freeze here. If it does, open a new shell and restart apache 2: | |
# sudo /etc/init.d/apache2 restart | |
sudo apt-get -y install apache2 | |
sudo /etc/init.d/apache2 stop | |
sudo apt-get -y install mono-devel mono-runtime | |
sudo apt-get -y install mono-apache-server4 | |
sudo apt-get -y install libapache2-mod-mono | |
# update permissions for r,w,exec for user + group | |
sudo chgrp -R www-data /var/www | |
sudo chown -R www-data /var/www | |
sudo chmod -R 755 /var/www | |
# Replace the default apache site settings | |
sudo mv /var/www/default.txt /etc/apache2/sites-available/default | |
sudo /etc/init.d/apache2 restart | |
# Install UFW (uncomplicated firewall) | |
sudo apt-get -y install ufw | |
# Allow SSH and HTTP traffic | |
sudo ufw enable | |
sudo ufw allow 22 | |
sudo ufw allow 80 | |
sudo ufw allow proto tcp to any port 135 | |
sudo ufw allow proto udp to any port 137 | |
sudo ufw allow proto udp to any port 138 | |
sudo ufw allow proto tcp to any port 139 | |
sudo ufw allow proto tcp to any port 445 |
<VirtualHost *:80> | |
ServerAdmin webmaster@localhost | |
AddHandler mono .aspx ascx .asax ashx .config .cs asmx .axd | |
MonoDebug default true | |
MonoSetEnv default MONO_IOMAP=all | |
MonoApplications "/:/var/www" | |
MonoServerPath default /usr/bin/mod-mono-server4 | |
DocumentRoot /var/www | |
<Directory /> | |
Options FollowSymLinks | |
AllowOverride None | |
</Directory> | |
<Directory /var/www/> | |
Options Indexes FollowSymLinks MultiViews | |
AllowOverride None | |
Order allow,deny | |
allow from all | |
SetHandler mono | |
</Directory> | |
<DirectoryMatch "/(bin|App_Code|App_Data|App_GlobalResources|App_LocalResources)/"> | |
Order deny,allow | |
Deny from all | |
</DirectoryMatch> | |
# remove this section if you don't need it | |
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ | |
<Directory "/usr/lib/cgi-bin"> | |
AllowOverride None | |
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch | |
Order allow,deny | |
Allow from all | |
</Directory> | |
ErrorLog ${APACHE_LOG_DIR}/error.log | |
# Possible values include: debug, info, notice, warn, error, crit, | |
# alert, emerg. | |
LogLevel warn | |
CustomLog ${APACHE_LOG_DIR}/access.log combined | |
</VirtualHost> |
I'm Chris Small, a software engineer working in London. This is my tech blog. Find out more about me via Github, Stackoverflow, Resume