Now that you have a nicely installed and updated system, it's time to get the Rails stack up and running. Let's start with installing the back end. You can use any database that can be installed on OpenBSD, however, I am going to use MySQL in this example. To start let's install the mysql-server package.

# pkg-add -i mysql-server
You will get a message when you have completed the install telling you to run the initial db creation so let's go ahead and do that now. First we have to start the server.

# /usr/local/bin/mysqld_safe &
# mysql_install_db
This will set up the initial tables for your database. Don't forget to set the root password!

# mysqladmin -u root password your_super_secret_password
Since we are going to be modifying some of our services at boot up, let's take a small detour and disable some services that aren't needed. You don't actually have to do this, but I would recommend it for the safety of the machine itself. Find and comment out the following lines in /etc/inetd.conf.

#ident           stream  tcp     nowait  _identd /usr/libexec/identd     identd -el
#ident           stream  tcp6    nowait  _identd /usr/libexec/identd     identd -el
#daytime         stream  tcp     nowait  root    internal
#daytime         stream  tcp6    nowait  root    internal
#time            stream  tcp     nowait  root    internal
#time            stream  tcp6    nowait  root    internal 
Now let's setup MySQL to start at bootup. First modify /etc/rc.conf

inetd=NO
Now add the following line into rc.conf.local

mysql=YES
Now enter the following in /etc/rc.local after the 'starting local daemons' and before the following echo '.'

if [ X"${mysql}" == X"YES" -a -x /usr/local/bin/mysqld_safe ]; then

    echo -n " mysqld"; /usr/local/bin/mysqld_safe --user=_mysql --log --open-files-limit=256 &

    for i in 1 2 3 4 5 6; do
        if [ -S /var/run/mysql/mysql.sock ]; then
            break
        else
            sleep 1
            echo -n "."
        fi
    done
fi
Now that MySQL is installed, let's get the rest of the stack running. The next piece is going to be ruby.

# cd /usr/ports/lang/ruby
# make all install clean
# cd /usr/ports/devel/ruby-gems && make install
# pkg_add /usr/ports/packages/i386/all/ruby-iconv-1.8.4p0.tgz
This will complete your setup of Ruby and rubygems. We can now complete the stack by installing Rails and Mongrel. You can always install any other needed gems, but that part is up to you.

# gem install rails -y
# gem install mongrel -y
This completes the install of the your stack and will get you up and running on rails. There is still a little bit of post install setup and cleanup left to do and I will post one more article in this series on adding new users, securing ssh from root logins, and setting up the firewall with pf. Stay tuned for more.
One of the first things you want to do is setup your environment for using pkg_add in interactive mode. To do so open the .profile file (at this point you don't have much of a choice in the way of editors here so VI is probably what you are going to use) and add the following lines

PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.1/packages/i386/
export PKG_PATH
Once you have done this, simply reload your .profile by sourcing it, or by logging out and back in. Now you have the ability to use the pkg_add system in interactive mode.

The first thing to do now is install a useable shell. Let's install bash and some other important tools that we will need later

# pkg_add -i bash
# pkg_add -i cvsup (when prompted choose the no-x11 version)
# pkg_add -i curl

Now let's grab the sys, src, and ports archives so that we can use them for updating later.

# curl -O ftp://ftp.openbsd.org/pub/OpenBSD/4.1/src.tar.gz (core system)
# curl -O ftp://ftp.openbsd.org/pub/OpenBSD/4.1/sys.tar.gz (kernel source)
# curl -O ftp://ftp.openbsd.org/pub/OpenBSD/4.1/ports.tar.gz (ports tree)

Now let's move these packages to the proper places and extract them.

# mv src.tar.gz /usr/src
# cd /usr/src
# tar -xvzf src.tar.gz

# mv sys.tar.gz /usr/src
# cd /usr/src
#tar -xvzf sys.tar.gz

# mv ports.tar.gz /usr
# cd /usr
# tar -xvzf ports.tar.gz
You now have the update framework in place for future updating of your system. Now let's create the cvsup files needed to run updates for your server. The first file you will create will update your src directories. Let's call it cvsup-src.

# Defaults that apply to all the collections
*default release=cvs
*default delete use-rel-suffix
*default umask=002
*default host=anoncvs3.usa.openbsd.org
*default base=/usr
*default prefix=/usr
*default tag=OPENBSD_4_1

# If your network link is a T1 or faster, comment out the following line.
# *default compress

OpenBSD-src
Now just copy the file you created and name it cvsup-ports. The only thing you need to change is the last line. Just change it from OpenBSD-src to OpenBSD-ports. Now that you have all of these things in place let's run cvsup and grab the latest versions of the source trees.

# cvsup -g -L 2 cvsup-src
# cvsup -g -L 2 cvsup-ports
After you have run this you will now have the latest version of the OpenBSD source. I would recommend that you follow the next couple steps for actually rebuilding your system but they are technically not required.

Rebuilding your world
After you have run the update scripts you can now start the rebuilding process. The first step is building your kernel. Here's how we do it.

# cp /bsd /bsd.old

# cd /usr/src/sys/arch/i386/conf/
# config GENERIC

# cd /usr/src/sys/arch/i386/compile/GENERIC/
# make clean && make depend && make && make install

This step will take a bit of time to complete. Once you have completed without errors just reboot to test out your new kernel. You're not quite done yet, you still have to complete this step with your ports tree as well as the system itself. Let's take a look at the ports tree.

# cd /usr/ports/infrastructure/build/
# ./out-of-date

This will give you a list of ports that are out of date and need to be recompiled. Since you don't have anything installed from ports yet it's not really a big deal. Now let's tackle the most time consuming part of our rebuild, the system.

# rm -rf /usr/obj/*
# cd /usr/src
# make obj
# cd /usr/src/etc && env DESTDIR=/ make distrib-dirs
# cd /usr/src
# make build

This will take a bit longer (usually somewhere around twice as long) than the kernel compile. Once you have completed successfully you can now reboot into your new running system.

That's all for this part of the tutorial. The next step will cover the ruby on rails stack install and basic application setup.
Theo and the OpenBSD team recently release OpenBSD 4.1. OpenBSD has been around for quite a while now and is recognized as the most secure operating system available. The development team goes to great lengths to ensure the quality of the code that gets put into the base distribution. I have just gone through rebuilding the server that runs this site and after deciding to put it on OpenBSD I have been nothing but pleased. This will be a multi-part set of articles demonstrating how to install and configure an OpenBSD server, and how to set it up for hosting a ruby on rails application.
There is an excellent site for anyone new to OpenBSD that details the installation, updating, patching, and several tips and tricks that will help you along the way. This site is called OpenBSD 101. I am not sure who maintains this site, but it is chock full of wonderful information.

The Install
Installing OpenBSD is actually quite easy given the proper information. For this first step I will refer you to OpenBSD 101. The installation section of this site is very well outlined and easy to follow. It can be found HERE. Follow these instructions and you will have a working OpenBSD system in just a short while. I know this first part seems kind of lazy on my part to just refer you to another tutorial, but I feel that it is well done and there is no need to copy it. This is also a good bit of information to take in and might take you a little bit of time to accomplish the first time you try it. Once you are finished you are ready to move on to part 2 of this tutorial which I will be publishing soon. That's all for now and stay tuned for more.
Since OpenBSD 4.1 was recently released i decided to give it a shot for hosting my site. I am now up and running on OpenBSD 4.1, but what's even cooler is the fact that I am running this site with rails under the default chrooted apache that ships with OpenBSD. This is really how a nice secure server should be. Stay tuned for a whole lot more on security, testing, and a full how-to on setting up a Ruby on Rails web server using OpenBSD 4.1