Rails on OpenBSD part 3 - Setting up Rails

July 29th, 2007

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.

Sorry, comments are closed for this article.

-U:**- index.html.erb   (Ruby RoR RHTML)
M-x visit-site http://aaronbedra.com