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 :
- Ubuntu 14.04 LTS
- Mono JIT compiler version 4.4.2
- 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://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
$ echo "deb http://download.mono-project.com/repo/debian 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 http://download.mono-project.com/repo/debian 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
$ 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
$ 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
$ 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 :
-
Ensuring Apache 2 running well at least by checking its version or start stop its service.
# apache version $ apache2 -v # start apache $ service apache2 start # stop apache $ service apache2 stop
-
Checking mono version
# mono version $ mono --version
-
Ensuring we have
/usr/bin/mod-mono-server4
Configuring Application Virtual Host
To configure virtual host application, the steps are
-
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# application directory $ chown -R -v your_user_name /var/www/
-
Lets create a simple
/var/www/hellodotnet/index.aspx
file.<center>mod_mono is working:<%=System.DateTime.Now.ToString()%></center>
-
Create a site configuration
/etc/apache2/sites-available/hellodotnet.conf
<VirtualHost *:81> ServerName hellodotnet ServerAdmin hello@test-apache-config.com 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 </Location> <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript </IfModule> </VirtualHost>
In this site I use port 81 instead of default 80.
-
Since we use port 81, we need to register port 81 in
/etc/apache2/ports.conf
by simply add the following codeListen 81
-
Enabling the site by running the following command from terminal
$ sudo a2ensite hellodotnet.conf
- Restart apache
- Hit from browser : http://localhost:81 We should have the page displayed current date time.
Tips
-
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
-
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 {} \;
-
If getting message could not find
/etc/mono/registry
, simply create the directory.$ sudo mkdir /etc/mono/registry
-
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
References
- http://www.mono-project.com/docs/getting-started/install/linux/
- http://stackoverflow.com/questions/34290004/how-to-install-configure-mod-mono-on-ubuntu-14-04-3-lts
- http://www.bloomspire.com/blog/2015/3/9/how-to-host-aspnet-applications-on-linux-p3
- http://superuser.com/questions/882594/permission-denied-because-search-permissions-are-missing-on-a-component-of-the-p
- https://www.codementor.io/tips/7134438372/access-to-the-path-etc-mono-registry-is-denied
- https://retkomma.wordpress.com/2011/10/01/registry-settings-in-mono-on-linux/