ModMono is an Apache module which provides ASP.NET support for Apache web server. We will be using Apache as an alternative for Microsoft’s IIS in Windows.
Part One: Installation
For ModMono to work first you need to install Apache. You can click here for instructions on how to install Apache. If you have already installed Apache, you can skip this step.
After that, install ModMono by executing the following command (single line). This will install ModMono with support for ASP.NET 2.0
sudo apt-get install libapache2-mod-mono mono-apache-server2
After the installation is complete, restart Apache and activate the ModMono module by executing the following commands:
sudo /etc/init.d/apache2 restart
sudo a2enmod mod_mono
Now we have to change the version ASP.NET to 2.0 in the configuration file. Open the config file in Gedit:
gksu gedit /etc/apache2/mods-available/mod_mono.conf
Once the conf file is open in Gedit, put a hash (#) in front of the line “Include /etc/mono-server/mono-server-hosts.conf” and delete the hash in front of “Include /etc/mono-server2/mono-server2-hosts.conf”. Now the two lines should look like this:
#Include /etc/mono-server/mono-server-hosts.conf
Include /etc/mono-server2/mono-server2-hosts.conf
Save the file and close it. Now restart Apache one more time
sudo /etc/init.d/apache2 restart
The installation is now complete.
Part 2: Testing
Now it’s time to test the installation. We are going to create a site called Ubuntu. But first we need to create a configuration file for this site inside the directory “etc/apache2/sites-available/”. To do this, execute the following command:
gksu nautilus /etc/apache2/sites-available/
This will open the directory in Nautilus. Now right-click inside the window and create a new empty file and name it “Ubuntu”. Then open the file using a text editor and paste the following text inside it, save and close.
Alias /Ubuntu “/var/www/Ubuntu”
AddMonoApplications default “/Ubuntu:/var/www/Ubuntu”
<Location /Ubuntu>
SetHandler mono
</Location>
(**Note: The formatting of the double-quotes in the above code have to be changed manually. Just delete all the double quotes and type them back again. Make sure you do this, otherwise it may not work.)
Now inside Nautilus, browse to /var/www/ directory and create a new folder called “Ubuntu”. Inside this folder create a new empty file and name it “index.aspx”. Then open this file using a text editor and type the following line of code in it. (Once again, don’t forget to delete and re-type the double-quotes.)
<% Response.Write(“It works like charm!”); %>
Save the file, close it and close Nautilus too. Then come the final steps where we enable the site and restart Apache one last time:
a2ensite Ubuntu
sudo /etc/init.d/apache2 restart
That’s it! Now open your web browser and point to: http://localhost/Ubuntu/index.aspx
You should see the text “It works like charm!” on the page.
Part 3 (Optional): Disabling a site
In part 2 we created a site called Ubuntu. Before we were able to view the aspx page properly we needed to enable the site in Apache. After we’re done testing there’s no need for the Ubuntu site anymore. Before you remove the files, you need to disable the site first.
Open a new Terminal window and execute the following command:
a2dissite Ubuntu
Now you have to remove the file “Ubuntu” we created in the “etc/apache2/sites-available/” directory:
cd /etc/apache2/sites-available/
sudo rm Ubuntu
Then we have to delete the “Ubuntu” folder inside the “/var/www/” directory (which contains index.aspx file) and restart Apache:
cd /var/www/
sudo rm -rf Ubuntu
sudo /etc/init.d/apache2 restart
Now you can close Terminal. Open your browser, clear cache and point to http://localhost/Ubuntu/index.aspx ; it will no longer work.
Note
Even if you have PHP5 and MySQL installed, installing ModMono won’t affect them. So you will be able to work with your PHP and ASP.NET files at the same time.
References:
Ubuntu Community and SqlServerDotNet. Parts 1 & 2 are mainly based on the information from these two sources, but I’ve added some steps in order to simplify the process even more.
February 17, 2009 at 1:13 am
cool
iwas try and it work
thank you so much
good job
regards
February 17, 2009 at 3:17 pm
Thanks a lot. I was totally lost in the wiki docs and all that stuff till I found this post.
April 4, 2009 at 6:10 am
I followed everything up until “That’s it! Now open your web browser and point to: http://localhost/Ubuntu/index.aspx” As when I click the link I get greeted by 503 Service error Service Temporarily Unavailable The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later. Maybe you know what the problem is?
April 8, 2009 at 11:44 am
After typing:
“sudo apt-get install libapache2-mod-mono mono-apache-server2″ and finish downloading I got this for long time:
Setting up mono-gmcs (1.9.1+dfsg-4ubuntu2) …
Setting up mono-apache-server (1.9.1-2) …
Setting up mono-xsp2-base (1.9.1-2) …
Setting up mono-apache-server2 (1.9.1-2) …
* Reloading web server config apache2 [ OK ]
* Restarting web server apache2 … waiting [ OK ]
What should I do?
April 8, 2009 at 12:19 pm
Hi,
After starting part 2 (testing), I got this error below:
** (nautilus:6503): WARNING **: Unable to add monitor: Operation not supported
Nautilus-Share-Message: Called “net usershare info” but it failed: ‘net usershare’ returned error 255: net usershare: cannot open usershare directory /var/lib/samba/usershares. Error No such file or directory
Please ask your system administrator to enable user sharing.
— Hash table keys for warning below:
–> file:///var/www/Ubuntu
–> file:///etc/apache2/sites-available
–> file:///var
–> file:///etc/apache2
–> file:///var/www
–> file:///
(nautilus:6503): Eel-WARNING **: “nautilus-metafile.c: metafiles” hash table still has 6 elements at quit time (keys above)
(nautilus:6503): Eel-WARNING **: “nautilus-directory.c: directories” hash table still has 6 elements at quit time
seahorse nautilus module shutdown
What should I do?
April 20, 2009 at 6:56 am
Works great until I try:
http://localhost/Ubuntu/index.aspx
Server Error in ‘/Ubuntu’ Application
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Resource URL: /Ubuntu/index.aspx
Version information: Mono Version: 2.0.50727.42; ASP.NET Version: 2.0.50727.42
I was on the CUSP of greatness!
April 23, 2009 at 11:56 am
Unfortunately this seems not to be true on Hardy (8.04). There is no way to have mod_php5 and mod_mono at the same time. Installing the one uninstalls the other.
April 25, 2009 at 1:43 pm
I’ve only tested this on Intrepid (8.10)
May 20, 2009 at 10:13 am
Every thing worked ok!!
Thank you!
June 11, 2009 at 2:12 am
Can you help me with this? Been googling for an hour with no luck.
Using VS2008 I “publish” (precompile) a site and copy it over to an Apache server running mod_mono (2.2). Run site, looks good.
Make a change, republish, recopy, run, still get old site.
There seems to be nothing I can do short of restarting Apache to get the new pages served.
There’s got to be a better way, right?
July 5, 2009 at 8:54 pm
[...] installing Apache, PHP, MySQL and phpMyAdmin, you can install support for ASP.NET files in Ubuntu. Don’t worry, you will be able to work with php and aspx files on the same Apache [...]
October 5, 2009 at 2:06 pm
Works great until I try:
http://localhost/Ubuntu/index.aspx
Server Error in ‘/Ubuntu’ Application
Process has not been started.
Description: HTTP 500. Error processing request.
Stack Trace:
System.InvalidOperationException: Process has not been started.
at System.Diagnostics.Process.get_ExitCode () [0x00000]
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_ExitCode ()
at Microsoft.VisualBasic.VBCodeCompiler.CompileFromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00000]
at Microsoft.VisualBasic.VBCodeCompiler.CompileAssemblyFromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00000]
at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromFile (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00000]
at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath, System.CodeDom.Compiler.CompilerParameters options) [0x00000]
at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath) [0x00000]
at System.Web.Compilation.BuildManager.BuildAssembly (System.Web.VirtualPath virtualPath) [0x00000]
at System.Web.Compilation.BuildManager.GetCompiledType (System.String virtualPath) [0x00000]
at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath (System.String virtualPath, System.Type requiredBaseType) [0x00000]
at System.Web.UI.PageParser.GetCompiledPageInstance (System.String virtualPath, System.String inputFile, System.Web.HttpContext context) [0x00000]
at System.Web.UI.PageHandlerFactory.GetHandler (System.Web.HttpContext context, System.String requestType, System.String url, System.String path) [0x00000]
at System.Web.HttpApplication.GetHandler (System.Web.HttpContext context, System.String url, Boolean ignoreContextHandler) [0x00000]
at System.Web.HttpApplication.GetHandler (System.Web.HttpContext context, System.String url) [0x00000]
at System.Web.HttpApplication+c__Iterator2.MoveNext () [0x00000]
Version information: Mono Version: 2.0.50727.42; ASP.NET Version: 2.0.50727.42
October 16, 2009 at 5:34 pm
Thanx this tutorial. But a have a question. After installition mod mono, PHP runs? I heard to damage PHP this module on ubuntu 8.04 Hardy? Did you tried?