ASP.NET MVC under Linux with Mono

Setup Mono on your Linux server

1. Install mod_mono

sudo apt-get install libapache2-mod-mono mono-apache-server4

2. Configure mod_mono

sudo nano /etc/apache2/mods-available/mod_mono.conf

 


AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascx
DirectoryIndex index.aspx

# Include the web application definitions generated by mono-server{2,4}-update.
#
# If you want to use ASP.NET 2.0 (via mono-apache-server2), use:
# Include /etc/mono-server2/mono-server2-hosts.conf
#
# If you want to use ASP.NET 4.0 (via mono-apache-server4), use:
# Include /etc/mono-server4/mono-server4-hosts.conf

Include /etc/mono-server4/mono-server4-hosts.conf

3.  Setup your Virtual Host

Prepare your public directory

mkdir /home/alduin/www

Make your directory readable by Apache

sudo chown -R www-data:www-data /home/alduin/www

Create apache configuration file

/etc/apache2/sites-available/default

 


ServerName yourdomain.co.uk
ServerAlias www.yourdomain.co.uk
ErrorLog /var/log/apache2/yourdomain.co.uk-error.log
CustomLog /var/log/apache2/yourdomain.co.uk-access.log combined
DocumentRoot /home/alduin/www/
 MonoServerPath yourdomain.co.uk "/usr/bin/mod-mono-server4"
 MonoDebug yourdomain.co.uk true # disable it in production
 MonoApplications yourdomain.co.uk "/:/home/alduin/"

<Location "/">
 Allow from all
 Order allow,deny
 MonoSetServerAlias yourdomain.co.uk
 SetHandler mono
 SetOutputFilter DEFLATE
 SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary

 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript

4. Restart Apache

sudo service apache2 restart

Upload your ASP.NET MVC application

1. Stuff you need to upload:

bin – all dlls
public – css, js
Views – all razor files
Global.asax
Web.config

ASP.NET MVC under Linux with Mono

Also you should upload these dlls to bin directory:

System.Web.Mvc.dll
System.Web.Razor.dll
System.Web.WebPages.dll
System.Web.WebPages.Deployment.dll
System.Web.WebPages.Razor.dll

Example

Here is an example of fully functioning website done using ASP.NET MVC 3:
http://greenstuffworld.com/

You may also like...

  • Pingback: xovilichter()

  • Pingback: top plumber in Austin TX()

  • Matt

    Is it possible to run asp.net mvc 4 or mvc 5??

    • R2D2

      I haven’t tried it yet. But I will try to get some demo running this weekend.

    • R2D2

      Yes you can, both actually.

  • Pingback: buy mobility scooters()

  • Michel Veloso de Andrade

    Hi,
    I tried this tutorial: httpmod-mono-server4://www.bytelinux.com/run-aspnet-apache-ubuntu/

    But I think MVC 5 does not working using “mod-mono-server4” only “xsp4”. =/

    • R2D2

      It does work. I managed to get it workin with mod-mono-server4