A day with .Net

My day to day experince in .net

Host ASP.NET in Linux

Posted by vivekcek on January 29, 2012

I think developing .net application with Linux will be cost effective.You don’t need to pay for Microsoft.But it’s in initial phase you wont get full advantage of

Microsoft .NET frame work in Linux.If you are interested can read about Mono project,sharp develop etc..

Today i am going to talk about hosting a .NET 2.0 web site in Linux.

Requirements
————

1. Ubuntu Linux 11.10(32 bit) or earlier.
2. Need high speed internet connection.

STEPS
—–

1. Install fresh copy of Ubuntu.Can be installed in virtual environment like virtual pc and VMware.
2. Open the Terminal (CNTRL+ALT+T).
3. Log-in as root:

vivek@ubuntu:~$ sudo -s -H

[sudo] password for vivek:
root@ubuntu:/home/vivek#

4. Install apache
root@ubuntu:/home/vivek# sudo apt-get install apache2

5. Check if Apache is working. Open Firefox browser and then paste this URL in the browser address bar then press enter:
http://localhost/

You should be able to see a page that says that Apache is working

6. Now install mod_mono:
root@ubuntu:/home/vivek# sudo apt-get install mono-apache-server2 libapache2-mod-mono

7. Enabling Mod_mono in Ubuntu
root@ubuntu:/home/vivek# sudo a2enmod mod_mono

8. Now to enable the auto hosting feature of mod_mono:
root@ubuntu:/home/vivek# sudo a2enmod mod_mono_auto

9. Restart Apache server:
root@ubuntu:/home/vivek# sudo /etc/init.d/apache2 restart

10. Change the owner of the www webroot to your Ubuntu username. By default the owner of the www webroot path (/var/www/) is the root. You need to change it to your

username for convenience. Follow the steps:
a.) In the command line, login as root.
b.) Go to the root directory
root@ubuntu:/home/vivek# cd /
c.) Go to /var/
root@ubuntu:/home/vivek# cd var
d.) Change the owner of the www to your username(replace vivek your own Ubuntu username):
root@ubuntu/var# chown -R codex-m:codex-m www
e.) Restart Apache server:
root@ubuntu:/home/vivek# sudo /etc/init.d/apache2 restart

11. Open a Text Editor copy the code

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>ASP.NET Test Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:label id="lbl1" runat="server">Hi, this is an ASP.NET Test Page! If you see this message then mod_mono module in Apache is working properly. Thank you!

</asp:label>
</form>
</body>
</html>


    

12. Save the file as testpage.aspx and save it to /var/www path.
13. In the web browser address bar, enter this URL and press enter:

http://localhost/testpage.aspx

The output in your browser should look like this:

Advertisements

One Response to “Host ASP.NET in Linux”

  1. Paramesh said

    Hi
    I followed the above porocedure with ubuntu version 12.04 and found the following results.

    1. While restarting apache server it resulted with an error condition

    sudo /etc/init.d/apache2 restart
    * Restarting web server apache2 [Sat Feb 16 13:37:10 2013] [warn] module mono_module is already loaded, skipping
    apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
    … waiting ..[Sat Feb 16 13:37:13 2013] [warn] module mono_module is already loaded, skipping
    apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

    2. On Launching the page in browser i observed the following error ocndition instead of the web page
    .

    Server Error in ‘/’ Application
    Parser Error

    Description: Error parsing a resource required to service this request. Review your source file and modify it to fix this error.

    Parser Error Message: The file ‘~/controls/MonoSamplesHeader.ascx’ does not exist

    Source Error:

    Line 1:
    Line 2:
    Line 3:
    Line 4:
    Line 5:

    Source File: /var/www/index.aspx Lines: 3, 3
    Version information: Mono Runtime Version: 2.10.8.1 (Debian 2.10.8.1-1ubuntu2); ASP.NET Version: 2.0.50727.1433

    Please let me know on resolving the issue.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s