Quantcast
Channel: source code bean » C#
Viewing all articles
Browse latest Browse all 10

Deploying your ASP.NET MVC3 site on Mono

$
0
0

In this blog post I am going to show you how easy it is to create a new ASP.NET MVC site and deploy it on Linux/Mono.

Step 1 – Create project
Create a new ASP.NET MVC 3 project. Compile and run it.


Step 2 – Add assemblies needed by Mono
Add references:
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor

Step 3 – Copy local
Make sure to set “Copy Local” to True for all of the following assemblies:
System.Web.Helpers
System.Web.Mvc
System.Web.Razor (C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.Razor.dll)
System.Web.Routing
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor

Remove Entity Framework and other unnecessary assemblies.

Step 4 – Publish your site
Publish it to a directory and copy it to your Linux server

Step 5 – Get latest Mono and compile it from source
I run Ubuntu 11.10 on my server. Ubuntu has Mono 2.10.6 in its repository, which is quite new, but Mono is moving so fast so I recommend getting the latest version and compiling it from source. The latest version at the time of writing is 2.10.8. Nathan Bridgewater has created a script to simplify this process, if you are running Ubuntu, this is what you will need to run to install Mono:

mkdir mono-2.10
cd mono-2.10
wget --no-check-certificate https://github.com/nathanb/iws-snippets/raw/master/mono-install-scripts/ubuntu/install_mono-2.10.sh
chmod 755 install_mono-2.10.sh
./install_mono-2.10.sh

It will take a while to compile it, so now is the time to go grab a cup of coffee.

Step 6 – Run your site with xsp4
Mono have a development web server called xsp4, the first thing we are going to do is to run our site in xsp4 to make sure it works. Mono has been installed to /opt, but does not exist in our PATH, so before we can run Mono we need to setup the mono enviroment variables. To do that I found a script somewhere on the internets, monoenv.sh:

MONO_PREFIX=/opt/mono-2.10
export DYLD_LIBRARY_FALLBACK_PATH=/lib:
export LD_LIBRARY_PATH=/lib:/opt/mono-2.10/lib:
export C_INCLUDE_PATH=/include:/include
export ACLOCAL_PATH=/share/aclocal
export PKG_CONFIG_PATH=/lib/pkgconfig:/lib/pkgconfig
export PATH=/bin:/opt/mono-2.10/bin:$PATH

At your bash prompt type: source monoenv.sh

Now cd into the directory where you have your published web site and run xsp4.

Now your MVC site should be up running on Mono!

In my next blog post I will cover how to configure your site to run using Nginx and the fastcgi-mono server.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images