Installing mono, apache, mod_mono and deploying applications in Ubuntu
Ok so i was kinda perturbed by the lack of documentation on how to install mod_mono on Ubuntu, and get it working on Apache so i decided to do some tinkering. So we will basically continue from the previous post that went through installing Mono on Ubuntu using XSP. So you ask??? Why should i even bother installing mono on Apache when it works perfectly well on XSP?
Well the answer is simple check out The official MONO FAQ for a complete explanation. But a short version is that XSP is not designed for full fledged production environments and the people at Mono have no intention of making this a reality an time in the foreseeable. Hence we have our ever reliable friend Apache!!!!!
Ok so we will begin with assumption that you have already installed Apache, and Mono and are looking to install mod_mono on Apache
1.
Open up your friendly old terminal and type in the following
$ sudo apt-get install libapache2-mod-mono
$ sudo apt-get install mono-apache-server2
$ sudo a2enmod mod_mono
The second command will assume that we are planning on running some ASP.net 2.0 applications on our server. While the third command will be to tell apache to activate the plugin that we have just installed via our apt-get. However we still need to tell Apache that we need to associate this new module with the various extensions that are associated with it.
2.
To do so we will need to edit the httpd.conf, and keeping in mind this is distribution specific, and here we are assuming Ubuntu Fiesty this is going to be in the /etc/apache2 directory.
$ sudo gedit /etc/apache2/httpd.conf
At which point our ever reliable editor gedit appears and we add the following line as the end of the file.
LoadModule mono_module /usr/lib/apache2/modules/mod_mono.so
3.
Ok so now we need to tell Apache where these files are going to be served. NOTE: you will have to do this step for each site that you want to setup using apache. This is so the server will know where the files with these particular extensions are and how they need to be handled.
To do this we crank up the trusty terminal once again and enter
$ sudo gedit /etc/apache2/apache2.conf
and paste in the following code at the end of the file.
<IfModule mod_mono.c>
#
# Allow remote server configuration reports, with the URL of
# http://servername/server-info (requires that mod_info.c be loaded).
# Change the “.example.com” to match your domain to enable.
#Alias /AspOnApache “/home/timani/web_dev/asp.net”
MonoApplications “/AspOnApache:/home/timani/web_dev/asp.net”
<Directory /home/timani/web_dev/asp.net>
SetHandler mono
<IfModule mod_dir.c>
DirectoryIndex index.aspx Default.aspx
</IfModule>
</Directory><Location /AspOnApache>
SetHandler mono
</Location></IfModule>
OK WHOA Nelly!!! Slow down a second and let us look at what we just did. What i hate is reading code that assumed to self explanatory. So a quick and dirty explanation is needed right quick.
A.
<IfModule mod_mono.c> and </IfModule> basically tells Apache what to do when it gets to an aspx file extension and how to handle it. Everything withing these two tags are directives that Apache will use to handle these files.
B.
Next we tell Apache that we are lazy and want to call the new location by an alias because we do not want to type the complete relative url path, and that the MonoApplications will be operating from the /home/timani/web_dev/asp.net path. Hence:
Alias /AspOnApache “/home/timani/web_dev/asp.net”
MonoApplications “/AspOnApache:/home/timani/web_dev/asp.net”
C.
Next to last we tell Apache that the directory /home/timani/web_dev/asp.net must be handled by the mod_mono, and that the default files that will serve as the index for this site in this directory will be index.aspx and Default.aspx.
<Directory /home/timani/web_dev/asp.net>
SetHandler mono
<IfModule mod_dir.c>
DirectoryIndex index.aspx Default.aspx
</IfModule>
</Directory><Location /AspOnApache>
SetHandler mono
</Location>
4.
WOW almost to the promised LAND!!!!!!!
Personally i do not like working in the default web root so i set up my file to be served from the /home/timani/web_dev/ directory as i said in the previous post. But we need to create a directory called “asp.net” because this is where we just told Apache to look for the aspx files. So do this by using your file manager so you now have a document structure like /home/timani/web_dev/asp.net.
Once this is done go to /home/timani/web_dev/asp.net and create a file called Default.aspx, and open it up in your trusty text editor, and paste in the following code, and save the file:
<%@ Page Language="C#" %>
<html>
<head>
<title> ASP.net on Apache Using mod_mono!!!</title>
<script runat="server">
void Button1_OnClick(object Source, EventArgs e)
{
HtmlButton button = (HtmlButton) Source;
if (button.InnerText == "Enabled 1"){
Span1.InnerHtml="You deactivated Button1";
button.InnerText = "Disabled 1";
}
else {
Span1.InnerHtml="You activated Button1";
button.InnerText = "Enabled 1";
}
}
</script>
</head>
<body>
<h3>WOW ASP.net on Apache Using mod_mono!!!</h3>
<form id=”ServerForm” runat=”server”>
<button id=Button1 runat=”server” OnServerClick=”Button1_OnClick”>
Button1
</button>
<span id=Span1 runat=”server” />
</form>
</body>
</html>
5.
FINALLY!!!!
Restart Apache to make sure that we make all the changes stick!!!!
$ sudo /etc/init.d/apache2 restart
Go to http://localhost/AspOnApache/ and VOILA we should see your new Page!!!!
It took a lot of time and effort so i hope that it works for you. Keeping in mind that there is still a lot of development that needs to be done be sure to keep an eye on what is going on at Mono and your hosting company. I am not sure of any hosts that will allow you to do this much configuration, but if they are already setup then that would be cool! Hopefully the interface on Monodevelop will be almost as intuitive as that of Visual Studio, and then that would be awesome!
Till next time enjoy the blog, and feel free to bookmark with veracity!
Filed under ASP.NET, General, Linux/Ubuntu, XML, mono |7 Responses to “Installing mono, apache, mod_mono and deploying applications in Ubuntu”
Leave a Reply
You must be logged in to post a comment.












[…] So, I’m going to have a shot at it again, this time following this post: Timani’s Blog » Blog Archive » Installing mono, apache, mod_mono and deploying applications in U… […]
Hi, thank you for this tutorial!, but sorry to bother, I can’t get it working. Here’s what I get: http://vlinux.homeip.net/simplerity .
Please
Thanks! This works perfect for me!
Thankyou….. works like a dream. You’ve saved me loads of time hunting around trying to figure this one out. Thanks again
Hi
Thanks for you guide its the best, I`v been searching but for no avail
However i have a problem when i restart apache i get the following error:
apache2: Syntax error on line 186 of /etc/apache2/apache2.conf: Syntax error on line 3 of /etc/apache2/mods-enabled/mod_mono.conf: Could not open configuration file /usr/local/lib/mono/2.0/mono-server2-hosts.conf: No such file or directory
…fail!
Thanks for your help
Awaiting your replies
Thanks - Justin
Hi wenek18 can u post your apache2.conf as well as your mod_mono.conf? its been a while since i did this but i can easily take a look at it for you.
[…] http://timanisblog.com/2007/07/22/install-mono-apache-mod-mono-applications-in-ubuntu/ […]