Science, Technology and Life

Mono Mod_mono Apache2 on Ubuntu

| Comments

I used to write a post about install and configure Mono on OS X Mountain Lion. On this post I want to summary what I did the similar things on Ubuntu.

The details environment I use :

  1. Ubuntu 14.04 LTS
  2. Mono JIT compiler version 4.4.2
  3. Apache 2.4.7

Install Mono, Apache 2, Mod Mono

To install Mono, the first step is add package repository to our system.

$ sudo apt-key adv --keyserver hkp:// --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

$ echo "deb wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list

$ sudo apt-get update

To enable mod_mono installation on Ubuntu 13.10 or later, and Debian 8.0 and later (and their derivatives), we need to add a second repository to our system, in addition to the generic Debian/Ubuntu repository above (if you don’t use sudo, be sure to switch to root):

$ echo "deb wheezy-apache24-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list

Then run package update to update and a package upgrade to upgrade existing packages to the latest available.

$ sudo apt-get update
$ sudo apt-get upgrade

To install mono, run the following command

install mono
$ sudo apt-get install mono-complete

If we do not have Apache 2 on our system, we need to install it first. Or we can check the existing version apache2 -v

install apache2
$ sudo apt-get install apache2

To be able to host ASP.NET application on apache, we need to install mod_mono. mod_mono is a module for the Apache HTTP Server that allows us to host ASP.NET pages and other assemblies on multiple platforms by using Mono.

To install Mod Mono and its dependencies run the following command

install mod_mono
$ sudo apt-get update && sudo apt-get install libapache2-mod-mono
$ apt-get install mono-apache-server4

Before going through the next step, the things than we can verify are :

  1. Ensuring Apache 2 running well at least by checking its version or start stop its service.

     $ apache2 -v
     $ service apache2 start
     $ service apache2 stop
  2. Checking mono version

    $ mono --version
  3. Ensuring we have /usr/bin/mod-mono-server4

Configuring Application Virtual Host

To configure virtual host application, the steps are

  1. Create a directory where the application physical files reside. In this sample I put my application files in /var/www/hellodotnet

    We needed to grant permissions to the login user so that the user could copy or create files to the hellodotnet directory. For our purposes we made the current user the owner of the directory

     $ chown -R -v your_user_name /var/www/
  2. Lets create a simple /var/www/hellodotnet/index.aspx file.

     <center>mod_mono is working:<%=System.DateTime.Now.ToString()%></center>
  3. Create a site configuration /etc/apache2/sites-available/hellodotnet.conf

        <VirtualHost *:81>
           ServerName hellodotnet
           DocumentRoot /var/www/hellodotnet
           MonoServerPath hellodotnet "/usr/bin/mod-mono-server4"
           MonoDebug hellodotnet true
           MonoSetEnv hellodotnet MONO_IOMAP=all
           MonoApplications hellodotnet "/:/var/www/hellodotnet"
           ErrorLog ${APACHE_LOG_DIR}/error.log
           CustomLog ${APACHE_LOG_DIR}/access.log combined
           AddHandler  mono    .aspx .ascx .asax .ashx .config .cs .asmx .axd
           <Location "/">
             Allow from all
             Order allow,deny
             MonoSetServerAlias hellodotnet
             SetHandler mono
             SetOutputFilter DEFLATE
             SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
           <IfModule mod_deflate.c>
             AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript

    In this site I use port 81 instead of default 80.

  4. Since we use port 81, we need to register port 81 in /etc/apache2/ports.conf by simply add the following code

     Listen 81
  5. Enabling the site by running the following command from terminal

     $ sudo a2ensite hellodotnet.conf
  6. Restart apache
  7. Hit from browser : http://localhost:81 We should have the page displayed current date time.


  1. If we get the page not displayed, we can see the message on the page displayed, HTML error code, or any clue on apache logs located in /var/log/apache2

  2. If we get message access denied cannot access bin, simply change permission of the application site.

     $ find hellodotnet -type d -exec chmod 755 {} \;
     $ find hellodotnet -type f -exec chmod 644 {} \;
  3. If getting message could not find /etc/mono/registry, simply create the directory.

     $ sudo mkdir /etc/mono/registry
  4. If getting System.UnauthorizedAccessException access to the path /etc/mono/registry, give access to it as its need, for example

      $ chmod uog+rw /etc/mono/registry