Filmmaker, Video Editor, Motion Graphics Designer, and Photographer in Cairo, Egypt.
Keeping notes to remember.. You may consider it some sort of Documentation.

Stay In Touch

Thursday, August 14, 2008

How To Configure ASP.NET websites On Ubuntu Localhost

To those who are interested in developing ASP.NET websites on Ubuntu operating system and mono platform, here's the steps to configure your website to the localhost.

1- Install Apache web server on your machine (you may use the Synaptic Package Manager for that).
2- Install Mod-Mono module, the Apache module responsible for serving and rendering ASP.NET pages.
3- Develop your website normally using MonoDevelop IDE.

Now, your application would run normally by the MonoDevelop. But, it still not configured on the localhost. So we need to create a " virtual directory" for the new website to be hosted. Virtual directors are made on 5 main steps. Let's assume that the new website we wanna to add in the local host is named "new_ASP_Solu", and the path of the default.aspx file is "new_ASP_Solu/new_ASP_Solu"

Step 1: Copy your solution in the /var/www directory
  • Write in the terminal the following command line:
$ sudo cp -r Desktop/new_ASP_Solu /var/www
  • sudo => is short for "superuser do", it allows a permitted user to execute a command as the superuser or root user.
  • cp => is short for "copy", it copies only on single file.
  • -r => an option added to some Linux commands to make it execute recursively. That's why we're using it here, to copy the whole directory :D
  • Desktop/new_ASP_Solu => the path of the solution. (It's just an assumption that it exists on the Desktop)
  • /var/www => the distention path, where we're coping the new website.
Step 2: Add a new virtual directory to the "Default"
If you opened the /etc/apache2/sites-available directory, you'd find one single file called "Default". This is where you should add the new virtual directory.
  • Open this file using this command:
$ sudo vi /etc/apache2/sites-available/Default
    • vi => is Linux text editor, use it to edit any file you wish.
  • Append the following code between the two tags <virtualhost> and </virtualhust>
<directory /var/www/new_ASP_Solu/new_ASP_Solu>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
SetHandller mono
DirectoryIndex Deault.aspx index.html
  • /var/www/new_ASP_Solu/new_ASP_Solu => the path of the default.aspx file.
  • SetHandller mono => determines the Apache module that will render this solution pages.
  • DirectoryIndex => it determines the website default (or starting) web page. In this case it's the Default.aspx, and for HTML it'd be the index.html.
Step 3: Create a file named "new_ASP_Solu.webapp"
  • Create a new file in /etc/mono-server2, with the same name of the solution, but the the extension .webapp
$ sudo touch /etc/mono-server2/new_ASP_Solu.webapp
    • touch => command creates an empty file.
  • Open this new empty file
$ sudo vi /etc/mono-server2/new_ASP_Solu.webapp
  • Add this code in it:
  • name => just give a name to your new web site.
  • vpath => the virtual path of your web page on the local host. In this case, if you typed in your web browser "http://localhost/new_ASP_Solu" it will open your solution.
  • path => the local path of your solution on your PC.
  • port => determines the port number to use.
Step 4: Add the new virtual directory in httpd.conf file
  • Open the httpd.conf file
$ sudo vi /etc/apache2/httpd.conf
  • Append the following:
MonoApplications "/new_ASP_Solu:/var/www/new_ASP_Solu/new_ASP_Solu"
<location /new_ASP_Solu>
SetHandler mono

Step 5: Restart Apache
This step is mandatory to run your website correctly.
$ sudo /etc/init.d/apache2 restart

Now, go to your web browser, type "http://localhost/new_ASP_Solu" in the address bar. Yep! It works!! ;) :D.