Installing OpenSuse 11.2 with Mono 2.6.1 and Apache Using Text Mode Configuration – Porting to Mono Part 1 of 3

I’ve always kept an eye on the Mono project, mostly out of curiosity and intrigue. The last time I played around with Mono it was at version 2.0, and at the time I didn’t really spend a lot of time on it because it didn’t support some of the things I was using.  Well recently, I regained interest in Mono when I saw it now supports MVC and some of Dblinq. And since I’ve been buzzing on the whole MVC thing for awhile, I decided to check Mono out for myself and start a fun little porting project. So this is the first part of a three part series describing everything I did to get a server up and running and one of my Asp.Net MVC applications ported to Mono.

This first part will cover installing and configuring an OpenSuse 11.2 server with Apache/Mono and SSH. The second part will talk about how to setup a MySql Membership provider (with mono and Windows), and the third part is a walkthrough showing how to port a simple Asp.Net MVC site to mono and MySql. I’m also targeting those of you who use virtual hosting where you might only have SSH (after install) to configure your server, so I will be using text based tools: SSH, vi, and yast for all my installations and configuration after getting the base system installed.

First off, let me just say that I’m a Windows .NET programmer; not a Linux programmer. I know enough about Linux to dig my way around most of the basic stuff, so if anything seems incorrect in this post, feel free to correct me. ;)  I’m extremely intrigued by Linux and its open source philosophy. I use it for a handful of useful, rock solid services like Subversion, Postfix, Samba file servers and MySql. I also share an interest with many small web shops in finding more affordable hosting solutions for smaller Asp.Net apps. And in light of Mono being able to run MVC apps, it’s very exciting to think of what we can do with it.



Before you Begin

There are a few things you need to download before you get started.  First of all, you’ll need an SSH client for file transfer and console access. I’m using FileZilla and Putty as my SSH clients. If you’ve never used it before, think of SSH like telnet and FTP wrapped into one.

Here’s a few tips on navigating the text mode installer screens. Use the Tab Key to cycle through fields or change focus between sections on the screen. Use the Spacebar or Enter to select an option. Esc can back out of a dropdown option. You can use the arrow keys to cycle options in a section.

Download one of the installers on OpenSuse’s website. Burn or mount the ISO and boot your machine from it to begin.

Note: while I was doing this on a test virtual machine, I could only get the Network install to work with Virtual PC 2007 on my hardware. All the versions worked fine when installing it to a physical machine. If you choose the network install, you may need to configure your DHCP settings before the GUI installer starts. (with Virtual PC, make sure the correct external network card is exposed to the virtual machine).

Installing Linux Graphical (part 1)

In sequence, here are (most) of the screens you’ll see during the first part of installing OpenSuse 11.2.

Configuring Linux During Install (part 2)

After the first phase, your computer will reboot and begin the manual configuration phase. As I mentioned earlier, these screens are pretty easy to navigate. Use tab to cycle through the fields or change focus to different sections. Use space or enter to make a selection. Also, the highlighted letters in words are hotkeys you can use in combination with the Alt key.  Each section will continue when you select the NEXT option in the bottom right corner.


Configuring Linux After Install

Root Access
You’ll need root access to perform most of the tasks we’re doing, so enter: su, then type the root password you configured during install. The command prompt will change color to red.

Updating Software

One of the really cool things about most Linux distributions is their package management. It’s a one-stop-shop for installing, updating, and removing software on your system. Fedora has yum, Debian has apt-get, OpenSuse has zypper. Using these utilities is very straight forward. So if you didn’t update your system during install, you can do it now by entering:

zypper update

You can run this command occasionally to update your system. To see more details about how to use it. Enter: man zypper


Install Mono, Apache, and MySql

Installing Mono and Apache

With zypper, we can cheat a little to install mono, apache, and all dependencies. First we need to add the mono repositories so zypper knows how to find it.

Enter the following lines separately:

zypper addrepo mono-stable  
zypper refresh --repo mono-stable  
zypper dist-upgrade --repo mono-stable

Our cheat is going to be installing Mod_Mono, which is the mono plugin for Apache. This will force it to install apache, mono, xsp and everything we need to get started.

zypper install mod_mono

Autostart Apache

To make apache start when the system reboots, enter this command:

chkconfig --add apache2

Installing MySql Server

To download and install mysql server and client, enter this command:

zypper install mysql

Add MySql to your startup and start it:

chkconfig --add mysql

service mysql start

Then configure the server with:


Follow the instructions and setup your server. The first question will be to enter your root password; the first time you run this, just press enter with a blank password, then choose Y to enter a new root password. You’ll also want to disable remote root access, the anonymous user, and test database.


Now setup your user account so you can remotely access the server. This also requires you to expose your MySql server over the Internet if you’re running a hosted server. Users in MySql are username & host based. Both parts make up a unique user.

To add a user:

Connect to your database server using your new root password. Enter: mysql -p

Here is an example of a user you would typically use for a specific application running on the local machine. This statement grants all privileges on a database called test_database and all its tables to a username ‘my_new_username’ who can only connect from localhost.

grant all privileges on test_database.* to 'my_new_username'@'localhost' identified by 'new_password' with grant option;

An admin user with access to everything from any location would have a statement similar to this:

grant all privileges on *.* to 'super_user'@'%' identified by 'super_secret_pw' with grant option;

Enter quit to exit the MySql client.


This is actually much simpler than it looks. I’m showing all these screens just for reference. Basically, just use yast as the tool configure the firewall. It has a nice little interface similar to the post-install configuration. For what we’re doing, add your network device to the External Zone, then add Secure Shell Server and HTTP Web Server to the allowed services. Then just enable and turn on your firewall (if it isn’t already on)


Configure a Virtual Host & Web Directory

I used the Mod_Mono configuration tool on the Mono website, which built the following configuration file. It looks big, but most of it’s comments. The key notes here are that it runs .Net 2.0, it’s root directory and that it handles all requests through Mono (good for MVC). It also does some nice things like compress the output on certain files as well as the Mono output.


<VirtualHost *:80>  
  DocumentRoot /srv/www/
  # MonoServerPath can be changed to specify which version of ASP.NET is hosted
  # mod-mono-server1 = ASP.NET 1.1 / mod-mono-server2 = ASP.NET 2.0
  # For SUSE Linux Enterprise Mono Extension, uncomment the line below:
  # MonoServerPath "/opt/novell/mono/bin/mod-mono-server2"
  # For Mono on openSUSE, uncomment the line below instead:
  MonoServerPath "/usr/bin/mod-mono-server2"

  # To obtain line numbers in stack traces you need to do two things: 
  # 1) Enable Debug code generation in your page by using the Debug="true" 
  #    page directive, or by setting <compilation debug="true" /> in the 
  #    application's Web.config
  # 2) Uncomment the MonoDebug true directive below to enable mod_mono debugging
  MonoDebug true

  # The MONO_IOMAP environment variable can be configured to provide platform abstraction
  # for file access in Linux.  Valid values for MONO_IOMAP are:
  #    case
  #    drive
  #    all
  # Uncomment the line below to alter file access behavior for the configured application
  MonoSetEnv MONO_IOMAP=all
  # Additional environtment variables can be set for this server instance using 
  # the MonoSetEnv directive.  MonoSetEnv takes a string of 'name=value' pairs 
  # separated by semicolons.  For instance, to enable platform abstraction *and* 
  # use Mono's old regular expression interpreter (which is slower, but has a
  # shorter setup time), uncomment the line below instead:
  # MonoSetEnv MONO_IOMAP=all;MONO_OLD_RX=1

  MonoApplications "/:/srv/www/"
  <Location "/">
    Allow from all
    Order allow,deny
    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

Edit the information above (or use the configuration tool) and replace my hostname with yours. Then save this file with the extension “.conf” and copy it to your /etc/apache2/conf.d directory using FileZilla SFTP connection as the root user.

Create a new directory at the location you specified in the DocumentRoot command. This is the root folder you’ll use to deploy your website.

cd /srv/www

mkdir my_web_hostname

After setting all this up, you’ll need to restart your Apache server. To do that, just enter:

service apache2 restart

You can restart any of your services this way. You might also reboot your server just to get a fresh run after installing and configuring all our software. Use the shutdown command to restart your system. Again, you can use shutdown --help or man shutdown to learn more about that command.

shutdown -r now

Running the Default Visual Studio MVC Website

This is cool! It’s a great start knowing that routing, controllers and views all work. Feel free to play with it a bit more. Mono has some great tools like MoMa that will tell you if your existing assemblies are compatible with Mono. You can also start toying around with Dblinq and alternative membership providers.


There’s more to come. The next post will show you how to use the MySql Membership provider with both Windows and Mono.


Useful Links