Running ASP.NET applications in Ubuntu using ModMono

Running ASP.NET applications in Ubuntu using ModMono

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.


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.

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”

SetHandler mono

(**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.

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:
ubuntuexperiment.wordpress.com

Leave a Reply

  

  

  


three + = 10