, ,

Edit: As pointed out in the comments (thanks Brian), turnkey now has a mod_mono stack:  http://www.turnkeylinux.org/asp-net-apache

I am in the process of moving a number of sites from a Windows shared hosting to a Linux virtual machine and one requirement is to be able to run ASP.NET. I need the VM to be quite stable so I went looking for an easy to way to create local virtual machines for testing and experimenting. I really did not want to spend time installing and configuring linux VMs and luckily I found the project TurnKeyLinux. This is a fantastic collection of ready to use virtual machines and ISO files with pre-installed software stacks such as LAMP servers, WordPress servers, file servers, etc, etc. The project is quite active and has a commercial arm that helps you host the virtual machines with Amazon. They don’t have a pre-packaged ASP.NET server but it is quite easy to create one as you will see. I started by downloading the LAMP Stack. I chose the VMDK image since my servers have VMWare Server installed. This is a small-ish 221 Mb zip file. I copied the zip file to the server, expanded it to a folder and added it to VMWare Server in the configuration site. As you turn it on and open the console (I am assuming here that you are familiar with VMWare server) the installation will prompt you for passwords for the root account and a few other services. It will also ask you if you want to use TurnKey’s backup service which you can skip and finally it will ask you if you want to update the machine with the latest patches. You can also skip this step because it will auto update itself later on. Finally the installation will finish with this screen:

Setting Up ASP.NET

Open a web browser and navigate to: which is a shell prompt to the virtual machine. Login with the root account and the password you set before and you should see a screen very much like this one:

You can install the software from this prompt or you can use an SSH client such as Putty. At this point we have a server with Apache 2, MySQL and PHP installed and running. You can navigate to the machine with a web browser and see TurnKey’s default page. The next step is installing mod_mono which is Mono’s Apache handler. All TurnKey builds derive from Ubuntu which is handy because Ubuntu is one of the best documented Linux distribution out there. I followed this page of installation instructions of mod_mono and although it is a bit out of date it has all the required instructions. In fact, since it was done for older builds of mod_mono and Ubuntu, it has more steps than the minimum required to serve ASP.NET pages so I am listing below what is needed as of March 2012:

1. In the prompt above start by typing apt-get update followed by enter. This will run a few processes and download a few files. You should answer Yes to any prompts.

2. Next you need to install mod_mono proper by typing apt-get install libapache2-mod-mono mono-apache-server2 followed by enter. This will take a while to process since it will download Mono, install it and configure Apache. You should also answer Yes to any prompts.

3. Then you need to enable mod_mono by typing the following: a2enmod mod_mono_auto

4. Finally restart Apache with the following instruction: /etc/init.d/apache2 restart

And that is it. The last step is to copy the ASPX pages and code files to the virtual machine for testing. Create a simple hello world ASP.NET page and code file and copy them to the root of the webserver which is at /var/www and navigate to the page. It should just work.

EDIT: It is also possible to install ASP.NET on the bare core TurnKey distribution. I used the TurnKey Core 12.0 RC ISO file. With it I created a virtual machine accepting all the defaults. After the machine was ready I went through the steps above but step 4 failed. I rebooted the machine and then run apt-get install apache2 which solved the problem and Apache is now happily serving ASP.NET pages. If your VM is short on memory or you just don’t need MySQL and PHP then this is a better choice although slightly more complicated to setup.

P.S. To copy the files to the virtual machine I suggest that you use Filezilla. You can find a very detailed tutorial on using Filezilla to connect to a Linux virtual machine here.

About these ads