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.

Index

 

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 http://ftp.novell.com/pub/mono/download-stable/openSUSE_11.2 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:

mysql_secure_installation

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.

Optional:

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.

Firewall

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>
  ServerName odin.integratedwebsystems.int
  ServerAdmin web-admin@odin.integratedwebsystems.int
  DocumentRoot /srv/www/odin.integratedwebsystems.int
  # 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 odin.integratedwebsystems.int "/opt/novell/mono/bin/mod-mono-server2"
  # For Mono on openSUSE, uncomment the line below instead:
  MonoServerPath odin.integratedwebsystems.int "/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 odin.integratedwebsystems.int 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 odin.integratedwebsystems.int 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 odin.integratedwebsystems.int MONO_IOMAP=all;MONO_OLD_RX=1

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

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

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

  1. One more thing. I am running OpenSUSE 11.2 in a VirtualBox instance and it is really slow. Did you install to the host on a machine or are you using virtualization? I’m thinking it is so slow because of a problem with it running specifically in VirtualBox. If you have any ideas…

  2. @Arwen
    Great! Glad to hear it! For this, I was using Virtual PC only because I had it installed and I wanted to try out the new Windows 7 one. It was pretty nit-picky when I installed this though. I usually use VirtualBox or VMWare if VirtualPC doesn’t work. I have used VMWare Server for production before, which worked out really well. I’d suggest trying out different options to see what works best on your host machine. Depending on your hardware, you may be able to take advantage of the virtualization optimizations there which could help speed things up.

  3. Dude you have made my day. Seriously this is a great article exactly what i needed. I have tried Zend framework before and it is also great, but i always wanted to have asp.net on Linux, and you are also right i am using this for a small web-shop. I do not want to pay money to MS for running Windows and IIS if I already have couple of sites running on redhat build on Zend. Anyway i was not paying even if i had to. In eastern Europe nobody does :) So at least now i am legal lol lol lol

  4. Nathan i needed to copy also the the System.Web.Mvc.dll reference into the bin directory in order for MVC to work! I hope this helps the others

  5. Thanks for the article it was really very helpful.

    One problem I had was that I used the mod_mono configuration tool – Which is useful but it defaults to setting the MonoServer path to:

    MonoServerPath Loot “/usr/bin/mod-mono-server2″

    But I built my application against .NET 4.0 so I needed to update the path to:

    MonoServerPath Loot “/usr/bin/mod-mono-server4″

    And everything worked :)

  6. @Jake Scott
    Great! Glad you got it working!

    Yeah, tweaking that virtual host config becomes more common when you start playing with the later versions of Mono or custom installs. On Ubuntu & Fedora, I setup a script that installs to a completely different path prefix; so it also requires setting the correct environment variables too.

  7. Hey,

    Thanks for the great tutorial. I’ve followed it almost per line but I am getting the following error when I launch a default sample web site built with VS 2010.

    Could not load file or assembly ‘System.IdentityModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL’ or one of its dependencies. The system cannot find the file specified.

    Did I miss something ?

  8. Thanks @Cyril!

    My apologizies. This post is quite old now. I’ve since learned that there are more ways to get recent mono installed to OpenSuse (always indicated on the mono-project.com Downloads page. Unfortunately the latest 2.10.5 (as of the time of this comment) isn’t yet available in official packages.

    Also regarding the MVC project you tested, is that MVC 1.0? One of the unwritten caveats is that this post was intended for MVC 1.0 since that was the only version available. I’ve more recently found that MVC2 is supported by 2.8, and MVC3 requires at least 2.10.2. Full MVC3 support including DataAnnotations model validation seemed to appear in 2.10.5 (the current).

    You can try a few things:
    1. First try just updating your mono install by doing, “zypper update”.
    2. You can try copying local any assemblies that report missing like this one. (This is the case in MVC2 and 3) System.IdentityModel resembles a core library, which makes me curious. I’m not familiar with that one specifically. In visual studio under the properties for that reference, just indicate Copy Local for the build action and rebuild/publish your solution.
    3. Try to zypper install mono-mvc and restart your apache server. (it may be named slightly different. You can zypper search mono | grep mvc to find the real name if it’s different.

    Good luck! I hope that helps!

  9. @Cyril
    Also, just wanted to mention. Some of my more recent posts refer to Ubuntu and Fedora. Fedora 15 is packaged with 2.10.2. Ubuntu is not, but it’s very easy to install it with a script if you’re comfortable compiling projects in linux. It’s just a little inconvenient to maintain as new releases are published.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>