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
- Installing Linux Graphical (part 1)
- Configuring Linux During Install (part 2)
- Configuring Linux After Install
- Updating Software
- Install Mono, Apache, and MySql
- Configure a Virtual Host & Web Directory
- Running the Default Visual Studio MVC Website
- Useful Links
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).
In sequence, here are (most) of the screens you’ll see during the first part of installing OpenSuse 11.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.
At this point, your operating system is installed and accessible online via SSH. (If you purchased a VM, this is where you’ll usually begin). To connect to your new server, open Putty and enter your static IP or hostname for your new server. Select SSH connection type. Then click Open. You will be prompted to trust the certificate. Click YES, and login to your new server using the account you setup during install.
NOTE: (You may optionally save these connection settings by typing a name and clicking Save.
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.
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:
You can run this command occasionally to update your system. To see more details about how to use it. Enter: man zypper
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
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)
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.
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
Open Visual Studio 2008 and build a brand new ASP.NET MVC Web Application. Publish it to a folder and copy all the published contents to your Linux server at /srv/www/my_web_hostname using FileZilla. Using a web browser, browse to your server and it should show that the new web application works right out the box (with the exception of Membership).
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.
- Mono Website – http://www.mono-project.com
- Mod_Mono Configuration Tool – http://go-mono.com/config-mod-mono/
- MoMa Mono Compatibility Checker – http://www.mono-project.com/MoMA
- OpenSuse 11.2 Download Page (scroll down) – http://software.opensuse.org/112/en
- OpenSuse Documentation (loaded with great how to documents) – http://en.opensuse.org/Documentation
- Putty Download Page – http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
- FileZilla Download Page – http://filezilla-project.org/download.php
- MySql Connector .NET Download – http://dev.mysql.com/downloads/connector/net/#downloads
- MySql Workbench (MySql Administration and Development tools) – http://dev.mysql.com/downloads/workbench/5.2.html