Unix System Administration » Web Servers

ID #1019

How to install Ruby on Rails on FreeBSD?

One of the development frameworks that grows most these days is Ruby on Rails, a framework to develop agile applications on the web using the object-oriented Ruby language.

In this tutorial you'll learn how to install Ruby on Rails with MySQL on FreeBSD. You need to have your ports up-to-date. Let's start installing Ruby on Rails:

% su-
# pkg_add -r rubygem-rails

This is going to install the whole Ruby on Rails framework with all dependencies such as Ruby. Now let's install Apache:

# pkg_add -r apache2

Now let's install FastCGI. We need to compile it from ports because we want it to support Apache 2 instead of 1.3:

# cd /usr/ports/www/mod_fastcgi
# make install clean

Now we have FastCGI. We are going to install MySQL with UTF-8 support, therefore we install from ports:

# cd /usr/ports/databases/mysql51-server
# make WITH_CHARSET=utf8 install clean

In a few minutes we have MySQL installed with UTF-8 support. Let's edit Apache's configuration file to be able to use FastCGI so that pages load fast:

# ee /usr/local/etc/apache2/httpd.conf

Add the following code in the end of the configuration file:

	LoadModule fastcgi_module     libexec/apache2/mod_fastcgi.so
	AddHandler fastcgi-script .fcgi

Now let's add a virtual host (adapt as you see fit):

<VirtualHost *:80>
ServerAdmin webmaster@example.com.br
DocumentRoot /usr/local/www/data-dist/rails
ServerName localhost/rails
ErrorLog /var/log/httpd/testapp-error_log
CustomLog /var/log/httpd/testapp-access_log common
Options Indexes ExecCGI FollowSymLinks
RewriteEngine On

Apache and FreeBSD don't work well together if you don't define a localhost host, so let's add it and also let's set Apache to start on FreeBSD bootup:

# ee /etc/rc.conf

Restart FreeBSD and then, let's create a directory for your Rails files in your home directory:

% cd /home/username
% mkdir rails
% cd rails

This version of Ruby on Rails has a bug but we'll fix it:

% su-
# ee /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/clean_logger.rb

Remove all content and paste:

require 'logger'

class Logger #:nodoc:
  # Silences the logger for the duration of the block.
  def silence(temporary_level = Logger::ERROR)
    old_logger_level, self.level = level, temporary_level
    self.level = old_logger_level

        if const_defined?(:Format) # Not defined in Ruby 1.8.3
                remove_const "Format"
    Format = "%s\n"
    def format_message(severity, timestamp, msg, progname)
      Format % [msg]

Now we just have to create a link (adapt as you see fit):

% cd /home/charles
% rails /home/charles/testapp
% cd /home/charles/testapp/
% ruby script/generate controller test
% su-
# cd /usr/local/www/
# rm data-dist (make sure the directory is empty)
# ln -s /home/charles/testapp/public data-dist

Now, Rails is fully working. Open http://localhost/ and you should see the welcome page of Rails.

Tags: -

Related entries:

Last update: 2007-01-11 17:01
Author: Charles A. Landemaine
Revision: 1.0

Digg it! Print this record Send to a friend Show this as PDF file
Propose a translation for Propose a translation for
Please rate this entry:

Average rating: 3.75 out of 5 (8 Votes )

completely useless 1 2 3 4 5 most valuable

You cannot comment on this entry

Comment of VzHRJoWkoFlhGnlBPx:
A good many valaulbes you've given me.
Added at: 2011-09-27 17:58

Comment of djsqLdjipiduusJ:
QAtbqQ , [url=http://fwbioaqgywko.com/]fwbioaqgywko[/url], [link=http://itwsrdpudhrv.com/]itwsrdpudhrv[/link], http://rhlutftrvyuy.com/
Added at: 2011-09-30 08:15

Comment of ICdJJFMLRS:
Your webitse has to be the electronic Swiss army knife for this topic.
Added at: 2012-02-16 02:28

Comment of NthGSvhNNGqn:
NTjTTB xmfflasoixkw
Added at: 2012-02-16 05:41

Comment of bvxJgYmRICIyIYirwL:
VHnqiT , [url=http://hyeafzovanlx.com/]hyeafzovanlx[/url], [link=http://tyxgqdhiepra.com/]tyxgqdhiepra[/link], http://vrfaamikakuw.com/
Added at: 2012-02-17 03:19

Comment of iVoaxfODPmwxsrQDJ:
4hYrrq irqfapdczfcy
Added at: 2012-02-19 11:35

Comment of LqYRtcWm28:
I am jealous, I am wkroing on my 12” Powerbook, which is a neat machine in many ways, but this term I am wkroing on XML, and some of the XML, and XSL documents can get out of hand. I would imagine that having more real estate would help in many ways.
Added at: 2013-11-17 01:00

Comment of WjzoFWQJH:
Patrick: Linux-Software-Entwicklung? Wenn es passt mfcsste ich nach dem aktuellen Headcount freagn, nicht, dass einer die zwei Planstellen geschluckt hat.Miri: als ich das gelesen hatte, lag ich mit Doppelcheeseburger und zwei Tequila Sunrise vom burgerbratenden U-Boot-Kapite4n auf dem Sofa im Fastkoma. War also durchaus entspannend....Sharon und ich haben audferdem mit seiner 4-je4hrigen Tochter gespielt. Sie hatte zwei Holzkatzen und mir hatte sie ihren Teddy zur Verteidigung gegeben...
Added at: 2013-11-17 16:44

Comment of nky4ryJXac6R:
Take note competitors, leardes scour the web looking for people writing about their company (good or bad) as a way to gather feedback. I had a feeling someone would be checking for posts another positive sign for linode.com IMO. Companies that don't really care don't need to find out what people are saying about them.
Added at: 2013-11-19 12:14

Comment of lupLe9N9Les:
Habe frfcher mal etwas VBA und JAVA Programmierung gemacht aderllings nur mit Win.. war eigentlich nicht ernst gemeint ;-) Momentan arbeite ich in der Reisebranche und lebe ich mit meiner Frau in Deutschland wobei sie jetzt immer f6fters wegen dem Essen in DE nf6rgelt.. ;-)
Added at: 2013-11-19 12:42

Comment of x4F4dIqX:
Hi Kamil,Thank you for your effort, it aclualty works. However one file at qtbase-winrt repository, namely /mkspecs/features/qt_build_paths.prf, contains your local path: E:\GitHub\qt5\qtbase\.qmake.conf so, please, either make this path relative or add a note that this file should be edited manually before the build.Also I've managed to build Qt5 for Windows Phone 8 x86 Emulator using -xplatform winphone-x86-msvc2012 option and x86 command line tools instead of arm. The only manual fix is adding path to rc.exe (resource compiler) to PATH in VS2012 x86 Phone Tools Command Prompt.Also I spend some time fixing generated .vcxproj file in order to build & run my sample app on WP8 Emulator, including:1. To it was added: Windows Phone 8.02. PlatformToolset was changed from v110 to v110_wp80 and so on.In general it works! Great!Regards, Pollen http://bcejljgbuos.com [url=http://uqtocqkw.com]uqtocqkw[/url] [link=http://xualejrktw.com]xualejrktw[/link]
Added at: 2013-11-19 20:05

Comment of VtnaeqY980:
Hello there:while trying to build the winRT I'm gitetng:Microsoft (R) Program Maintenance Utility Version 11.00.50727.1Copyright (C) Microsoft Corporation. All rights reserved. cd bootstrap\ && ( if not exist Makefile H:\Deve\qt-5.0.2\qtbase\bin\qmake H:\Deve\qt-5.0.2\qtbase\src\tools\bootstrap\bootstrap.pro -o Makefile ) && nmake -f MakefileProject MESSAGE: H:\Deve\qt-5.0.2\qtbase\bin\syncqt.bat -minimal -module QtCore-module QtDBus -module QtXml -mkspecsdir H:/Deve/qt-5.0.2/qtbase/mkspecs -outdir H:/Deve/qt-5.0.2/qtbase E:\GitHub\qt5\qtbase -module QtZlibE:\GitHub\qt5\qtbase: No such file or directory at H:\Deve\qt-5.0.2\qtbase\bin\syncqt line 584.using the command lines you provide in this page.I cannot find where the E:\GitHub\qt5\qtbase' is set,can you help me on this?many thanks,G http://okwobiurz.com [url=http://zymcymxdd.com]zymcymxdd[/url] [link=http://lqaddhbrg.com]lqaddhbrg[/link]
Added at: 2013-11-19 20:27

Comment of K1y0sq13KH:
car insurance quotes share cheap Auto Insurance Quotes in all states automobile insurance brokers link
Added at: 2014-01-03 19:08

Comment of G5ECRCiq:
www.gettinginsurancequotes.net credit cards insurance coverage car rental Cheap Car Insurance Quote www.edproductsonline.com health insurance
Added at: 2014-01-05 00:11

Comment of HBWJURGL:
prozac sales online slot machine games auto insurance comparason tool website news blackjack prednisone
Added at: 2014-01-13 11:58