Now we have the Apache web server running on our server, but we have not installed any of the packages we need to run ASP.Net applications. We could install run-times that would allow us to build web applications in PHP, Perl, or Python, but I am going to install Mono so we can use C# / .Net. This is the language I am most familiar with so it is nice choice for me. Unfortunately, installing and configuring Mono is not quite as easy and straight forward as the PHP runtime. I may write a blog entry for PHP as well since so many of the existing open source GIS technologies favor it.
Make sure to stop Apache using the command below before installing Mono because it can cause problems otherwise.
$ sudo /etc/init.d/apache2 stop
Now run the following commands to install Mono for a production environment.
$ sudo apt-get install mono-apache-server $ sudo apt-get install mono-apache-server2 $ sudo apt-get install libapache2-mod-mono
I think you could run the following as well, but it installs a bunch of additional packages that you may not need...
$ sudo apt-get install mono-complete
Now we need to configure Mono. This was very confusing to me because I couldn't find really good documentation anywhere, so this section is really a work in progress. This works but I can't say I understand all the options fully.
You can use the a2enmod and a2dismod commands to enable and disable virtual hosts in Apache. These commands create link files in the sites-enabled folder and Apache parses the contents when it is reloaded.
$ sudo a2dismod mod_mono $ sudo a2enmod mod_mono_auto
Enabling mod_mono_auto seems to setup the parameters that you would want for all ASP.Net sites that you might host on this server. I think this is called autohosting and basically the remaining configuration options are set in the virtual host file for the specific website so you don't have to make configuration changes to Apache in order to control how Mono works in your web applications. This is nice but requires a few more options to be understood and set correctly. You can see that even the version of the .Net framework is set within the virtual host file.
Now to get a test Mono web application running let's create a new virtual host file, enable it , and have it "point" to a simple web application. You can go to the mono website and use their little wizard to create your virtual host file. This is probably the best way to do it...
I added lines 13 and 14 in order to make it run using the 3.5 framework, but now you can run the command below to enable the virtual hostsite...
$ sudo a2ensite <myvirtualhost>
Of course the actual ASP.Net web application needs to be in place and located at the path /home/<user>/www as you can see above in the virtual host file. Create a simple test file in this directory called default.aspx and fill it with some really simple code just to make sure all is working. Here is a little snippet to copy and past...
<%@ Page Language="VB" %> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) lblVersion.Text = "Your server is running ASP.NET and the version is " & System.Environment.Version.ToString() End Sub </script> <html> <head> <title>ASP.NET Version</title> </head> <body> <form id="form1" runat="server"> <asp:Label ID="lblVersion" runat="server"> </asp:Label> </form> </body> </html>
This just writes out some text to a Label webcontrol, but if you see the text, then Mono / ASP.Net is working. If not, you done screwed it up.
Oh, don't forget to restart the Apache webserver firstand see if it will even load using...
$ sudo /etc/init.d/apache2 restart
If you see an error that looks like this you can ignore it. It is an unfortunate error but doesn't actually cause any problems. I think it is fixed in a future release of Apache2 or Mono...not sure and don't really care much since it still works fine.
Now you can pull up a browser and navigate to the URL of the website you setup and it should work.