Mono on OS X 10.8 Mountain Lion

In this post I will write about setup and configure mono on OS X. I need mono on my Mac since C# is one of my favorite programming language ;)

First of all let’s download Mono SDK and MonoDevelop. The order installation is Mono SDK first then MonoDevelop. The installation of Mono SDK and MonoDevelop should be easy by following the installation wizard.

When the installation finish, open terminal :

# mono version
mono -V

We should get info about the version of mono installed in our machine.

Try to create an ASP.NET Web Application project by selecting menu : File > New > Solution. Select C# > ASP.NET > Web Application

Click Run > Run With > Mono Soft Debugger for ASP.NET

ASP.NET on Apache Web Server

To run ASP.Net on Apache web server, we need Mod mono module. It is an Apache 2.0/2.2 module that provides ASP.Net support for Apache web server. The steps installation are :

  1. Install Apache web server. The steps for OS X Mountain Lion can be found in my previous post
  2. Install Xcode, OS X development tool. It’s free and can be downloaded via App Store. We need it to compile mod mono installation source
  3. Download Mod mono source installation here. At the time of write this article I use mod_mono-2.10.tar.bz2
  4. Install mod mono module. Open terminal
    # mod mono installation
    mkdir ~/modmono
    cp ~/Downloads/mod_mono-2.10.tar.bz2 ~/modmono
    cd ~/modmono
    tar xzf mod_mono-2.10.tar.bz2
    cd mod_mono-2.10
    ./configure
    make
    sudo make install
    sudo cp /etc/apache2/mod_mono.conf /etc/apache2/other
  5. Add mod_mono.conf reference in httpd.conf
    sudo vi /etc/apache2/httpd.conf
    Add the following code at the end of httpd.conf
    Include /etc/apache2/mod_mono.conf
  6. Create a web directory with the path ~/Projects/Mono/TestMonoApache/TestMonoApache/ In that directory create an index.aspx file
    <center>mod_mono is working:<%=System.DateTime.Now.ToString()%></center>
  7. Add an Apache configuration file for mono.
    sudo vi /etc/apache2/mod_mono.conf
    Add the following line at the end of mod_mono.conf
    Alias /testmono "/Users/username/Projects/Mono/TestMonoApache/TestMonoApache/"
    <Directory "/Users/username/Projects/Mono/TestMonoApache/TestMonoApache/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
    
        Order allow,deny
        Allow from all
    </Directory>
    AddMonoApplications default "/testmonoapache:/Users/username/Projects/Mono/TestMonoApache/TestMonoApache/"
    <Location /testmonoapache>
     SetHandler mono
    </Location>
  8. Restart apache server with command :
    sudo /usr/sbin/apachectl restart
  9. Open browser and hit http://localhost/testmonoapache/index.aspx

Cool, now our apache web server can receive request for asp.net page. Thanks for reading and see you in the next post :)

References

  1. http://www.mono-project.com/Mod_mono
  2. http://blog.coultard.com/2012/04/developing-using-c-and-mono-on-mac.html
  3. http://www.ienablemuch.com/2010/10/aspnet-on-mac-os-x-snow-leopard-at-one.html