Arch Linux + lighttpd + Mono == ASP.NET MVC 3

I had a time getting my cheap linux box hosting configured to host my ASP.NET MVC 3 application. These notes are how I got it working using mono 2.6.10 on my Arch Linux 200510

In this example I setup a directory to host my application (I will get to what files and how later) I placed these files in the ‘/srv/http/mysite’ folder.

1. Install mono, lighttpd and fcgi on the box

pacman -Sy
pacman -S mono lighttpd fcgi

2. Setup lighttpd to use FastCGI edit the ‘/etc/lighttpd.conf’ file and modify this line;

server.document-root    = "/srv/http/mysite"

3. Add this line to the end of your ‘/etc/lighttpd.conf’ file;

include "fastcgi.conf"

4. Put this into your ‘/etc/lighttpd/fastcgi.conf’ file;

include "mono.conf"
server.modules += ( "mod_fastcgi" )
fastcgi.server = (
        "" => ((
                "socket" => mono_shared_dir + "fastcgi-mono-server4",
                "bin-path" => mono_fastcgi_server,
                "bin-environment" => (
                        "PATH" => "/bin:/usr/bin:" + mono_dir + "bin",
                        "LD_LIBRARY_PATH" => mono_dir + "lib:",
                        "MONO_SHARED_DIR" => mono_shared_dir,
                        "MONO_FCGI_LOGLEVELS" => "Standard",
                        "MONO_FCGI_LOGFILE" => mono_shared_dir + "fastcgi.log",
                        "MONO_FCGI_ROOT" => mono_fcgi_root,
                        "MONO_FCGI_APPLICATIONS" => mono_fcgi_applications
                ),
                "max-procs" => 1,
                "check-local" => "disable"
        ))
)

5. Put this in your ‘/etc/lighttpd/mono.conf’ file;

index-file.names += ( "index.aspx", "default.aspx", "Default.aspx" )
var.mono_dir = "/usr/"
var.mono_shared_dir = "/tmp/"
var.mono_fastcgi_server = mono_dir + "bin/" + "fastcgi-mono-server4"

### The root of your applications
# For apps installed under the lighttpd document root, use:
var.mono_fcgi_root = server.document-root

### Application map
# A comma separated list of virtual directory and real directory
# for all the applications we want to manage with this server. The
# virtual and real dirs. are separated by  a  colon.
var.mono_fcgi_applications = "/:."

Make sure you didn’t fat monkey up the conf files by doing this;

$ lighttpd -t -f /etc/lighttpd/lighttpd.conf

Should return a “OK”

Now go into your ASP.NET MVC app and setup the references to be “Copy Local” True on these assemblies (if you don’t have the assembly reference by the project add it, you might need to look in “Assemblies -> Extensions” to find some of these) ;

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

Make sure you DO NOT have the Microsoft.Web.Infrastructure.dll file, it doens’t work with Mono and causes errors.

Now just publish your project to a folder somewhere, then go into that folder and get the entire contents to the ‘/srv/http/mysite’ folder. Sure you can setup FTP and all that fanciness but I just use WinSCP and copy directly from my publish folder into the ‘/srv/http/mysite’ folder.

Now start lighttpd on the box and you should have the joy of ASP.NET MVC 3.

Enjoy!

References;

http://www.mono-project.com/Release_Notes_Mono_2.10#ASP.NET_MVC3_Support
http://redmine.lighttpd.net/wiki/1/Docs:Configuration
https://wiki.archlinux.org/index.php/Lighttpd
http://www.mono-project.com/FastCGI_Lighttpd