Installing Ruby on Rails with Lighttpd and MySQL on Fedora Core 4

Contents

Introduction

This how-to is aimed at getting you started with Ruby on Rails installed on the Fedora Core 4 Linux distribution using the Lighttpd web server and mySQL database server.

Why use this combination of Fedora Core 4 (FC4) and Lighttpd? Well, lets start with FC4. Fedora aims to be a complete, general-purpose open source operating system that is designed to be easily installed and configured with a simple graphical installer. Packages and their dependencies can be easily downloaded and installed with the yum utility. FC is updated regularly with new releases of Fedora come out every six months.

Fedora was born from the original Red Hat Linux distribution and aims to be a conventional Linux home users will use. This makes it a perfect platform to setup up our Rails server.

I chose Lighttpd as it natively supports two core features that rails requires out of a web server - Fastcgi and URL rewriting. FastCGI is removes a lot of the limitations of CGI programs. CGI programs have the problem that they have to be restarted by the web dedicated server for every request which leads to really bad performance values. FastCGI removes this limitation by keeping the process running and handling the requests by this always running process.

Lurking in the Ruby on Rails Wiki, many Rails experts seem to feel that Lighttpd is the best server platform for running Rails.

You may be wondering why you might want to install Ruby on Rails with FC4 when you could just as easily install it on your Windows or Mac box. Well, when experimenting with new development frameworks (such as Rails) I tend to avoid installing such software on my production systems. The last thing I need is to bring my everyday systems down due a bad software install or system conflict. So I try to install experimental technologies on separate, old, spare systems. And Linux makes alot of sense as the OS is free.

Disclaimers

Before you begin this how-to, I feel it is important to be aware that I am by no means a Linux expert. Although I have used Linux to run Apache and Mail servers for my personal use, I do not use Linux in a professional environment. So the information provide here is simply provided by that of a web developer who enjoys hacking around in Linux. Having said that, I have installed this mix of OS and applications over 10 times while preparing this how-to, so I am sure that you will have no problems if you follow along.

If you're new to Linux, you should follow this how-to by installing the OS on an old system. If you have some experience, you can install FC4 so that it co-exists with your Windows OS - but make sure you know what you're doing before you try this!

Let's get started!

Getting Fedora Core 4

You can obtain Fedora Core 4 from the Fedora website. Visit their downloads page and grab the distribution that matches your platform (i386 is for Intel based systems, x86_64 is for 64-bit processors, and ppc is for Mac based computers). If you have a DVD-ROM drive that you can boot from, I would recommend downloading the DVD ISO image as you won't have to swap discs during the installation process. If you have a bittorrent client, you might also want to download FC4 using a torrent. This is from my experience the fastest way to download FC4.

Once you have downloaded the appropriate ISO disc image, you can burn it using your favorite CD burning software like Nero.

Installing Fedora Core 4

This section is intended to be a brief summary of installing FC4 and should be enough to get you going. If you're interested in finding out more about installing FC4, you can view a very detailed installation document at the Fedora website.

Installing FC4 is a very straight forward process. In fact, I think it may even install easier than Windows. FC4's driver support is excellent, and the installer walks you through the installation process in just a few simple steps. So let's get started! Place your FC4 CD or DVD into your optical drive and startup your computer (Note: you will have to configure your system BIOS to boot from your optical drive). Turn on your computer and wait for the installer to begin. The first prompt you will get will ask you if you want to examine your installation media. This is a good idea, as it will confirm that your download worked. Once the installation media has been tested, you will taken to FC4's GUI based installation.

First you'll be asked to choose your language and keyboard. Choose the one that best suits your needs. Next, you will be asked to Install Fedora Core or Upgrade an Existing Installation. Choose to Install Fedora Core. On the next screen, you will be asked to choose an installation type. You want to choose Custom. A key security strategy while using Linux as a server, is to install only the services that you need. Choosing Custom here, will let us pick only what we need.

The next screen asks you how FC4 should parition your hard-drive. I am assuming that you are installing this on a computer that currently has no other operating system. If this is the case, choose Automatically Partition. If you would like to dual-boot with another OS, you should stop here and do some research on dual-booting Linux with another OS. This is beyond the scope of this how-to. On the next three screens, accept the defaults.

Next you can configure your Network Devices. Enter you TCP/IP settings much like you would in Windows (ie. DHCP, Gateway, DNS. On the next screen you will be asked to enable the built-in firewall. At this point, you should choose to Enable Firewall and allow access to the SSH and HTTP services.

Next, you will be asked to type in a Root Password. The root account is available on all *nix based operating systems and is used to help you administer your OS. Normal users, cannot perform many administration tasks unless they temporarily give themselves root access permissions. By setting the root password, you will be able to provide yourself with this privelege. So type in a password that you will not forget, but at the same time is secure (at least eight characters, at least one character being a numeric and one character being uppercase).

Next you will need to choose which packages should be installed. You can keep all the defaults with the exception of the following:

Now click the Next button. Click Next again to begin installing the FC4. Once the packages have been installed, you will be prompted to reboot your system. Choose to reboot, and FC4 will start up for the first time at which point you will be walked through a wizard where you will setup the date and time, choose a display and other tasks.

The most notable setting here, is to enter a system user. Choose a username for your own login account then enter a username and password and click next then continue to click next until you are prompted to Finish the installation.

That was it! If all went well, the entire installation process should have taken about 20 minutes! Try that with Windows!

Now we need to login for the first time. Before you enter your username and password though, let's choose a session type. Near the bottom of the login screen, you will see a button titled Session. Click this button and from the list of options that appear, select GNome. Now type in your username and press enter, then type in your password and press enter.

Linux Administration

To perform many Linux administration tasks, you need to be logged in as the root account. But in Linux, it is a bad idea to login as the root user. Instead, we log in as a regular user, then switch to a root user only when needed via the terminal. To give us this administrative power, we prefix many of our terminal commands with the sudo command. Sudo (superuser do) allows a system administrator to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while logging the commands and arguments.

Initially we have a problem using the sudo command, as the system user is not a member of the sudoers list. To fix this, we need to edit a file named sudoers.

But, there is a hiccup here, because to edit the sudoers list, we must be logged in as the root user - which if you remember is a bad idea in Linux. So what we will do here, is open a terminal window and create a root terminal session. This make terminal think that we are logged in as root.

Lets start by opening a new terminal window. Click on the Applications menu located at the top-left of your desktop, then choose the System Tools submenu then choose Terminal. Now lets create the root terminal session by using the su command which allows us to temporarily switch to the root user. So from the terminal window that you just opened, type:

su

then press enter. You will be asked to type into your password at which point you will type in the Root password you supplied when you installed FC4. Once you password has been accepted, you will now be typing and running command in the terminal as the root user!

Now lets edit the sudoers file by typing the following command into the terminal:

gedit /etc/sudoers

A graphical editor should now appear with the sudoers file open. Scroll down the file until you see a line that reads:

# User privilege specification
root          ALL=(ALL)      ALL

and copy and paste it immediately below that line. Then change the word root to the same username as you chose for you system user. Your User privelege specification should now look like this:

# User privilege specification
root          ALL=(ALL)      ALL
yourUserName  ALL=(ALL)      ALL

Click te Save icon on the toolbar, then close the editor window.

Finally we will end our root terminal session by typing the following command into our terminal window:

exit

YUM

What is Yum?

YUM, or Yellow Dog Updater Modified, is a program that allows users to easily update, add or remove packages on their Linux systems. YUM provides a command-line interface to managing the packages that are available as RPM (Red Hat Package Manager) files. YUM communicates with repositories that contain a database of rpms and headers. The rpms contain the actual program and data that you would like to install and the headers contain information about the dependancies that are required by the program you are attempting to install. So if you want to install program x, you simply type yum install x and YUM will download and install program x as well as any other programs that are required by program x.

Looking for a more permanent Rails hosting solution?

Dreamhost offers great Rails hosting packages. Signup now and enter the promotion code dmmrails to recieve $70 of your first year of hosting. Your total cost for one year will be $49 - that's only about $4 per month!
Signup Now!

Installing Yum Extened GUI

The Yum program is commonly run from a terminal window, but if you're like me, you may prefer to use programs that have graphical user interface(GUI). Throughout this how-to we are going to attempt to use GUI's whereever possible and we'll try to keep our time using the command-line terminal to a mimimum. The first program we are going to install is Yum Extender which is a program that allows you to install, update and remove packages from GUI. It makes viewing and managing Fedora packages very easy.

To get Yum Extender, we are going to use the YUM command-line program. If your terminal window is not open, open it now. When we use YUM, we must be a root user, so we will make sure we use the sudo command to temporarily give us that access. So we can install Yum Exender by typing:

sudo yum install yumex

You will now be asked to enter your password by the sudo program. Type in the password you used for your system account and press enter.

As this is the first time you have run YUM, it will spend a bit of time downloading and initializing the YUM repositories, then you will finally be prompted whether or not you want to install Yumex. Select yes, and yumex will be installed. Now lets close the terminal window.

Upating Fedora Core 4

Now lets update our FC4 installation using Yum Extender. Keeping your FC4 installation up to date is very easy and an important task that you should run as often as possible. This will help keep your FC4 linux as secure and bug-free as possible. Updates to FC4 software happen on almost a daily basis!

We begin by running Yum Extender by clicking on the Applications menu, then choosing System Tools then choosing Yum Extender. It's worth noting that Yum Extender needs to be run by the root user, so when you start Yum Extender, you will be asked for your root password. Type the password in when prompted and then click the OK button.

A nice simple GUI appears and the program will once again update the YUM repositiores and check to see which existing packages need to be updated. Once Yum Extender has finished updating its package list from the repositories, you will see a list of all installed packages on your system that need to be updated. Click the Select All button at the bottom of the Yum Extender window, then click the Update button. Follow the prompts and wait for the updates to download and install, then we will move on to the next step. Note do not close Yum Extender as we will continue to use it for the next few steps.

Installing Ruby on Rails

Our next step is to begin installing Ruby on Rails. This is a three step process that requires us to install the Ruby programming language, followed by Ruby Gems (much like YUM but for Ruby extensions) then finally Rails. Please note that if you've installed Rails before, DO NOT install the RubyFCGI Gem as it causes problems on FC4 and Lighttpd.

Installing Ruby

To install Ruby, while still in YUM Extender, click on the Install icon that is located on the left toolbar. Now we can search for uninstalled Ruby packages by typing Ruby into the filter textbox near the top of the Yum Extender window then pressing the Enter key on your keyboard. Now you should see a list of all Ruby related software that can be installed on your FC4 system. The packages that we need and the ones that you place check marks next to are:

Once you have selected these packages, click the Install button at the bottom of the Yum Extender window, follow the prompts and wait for the packages to download and install, then we will move on to the next step.

Installing Ruby Gems

To install Ruby Gems, we'll need to go back to a Terminal window and type the following commands (pressing enter at the end of each line):

wget http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
tar zxvf rubygems-0.8.11.tgz
cd rubygems-0.8.11
sudo ruby setup.rb

 If all goes well, you should see a message that says Successfully build Ruby Gems.

Now lets cleanup the files we downloaded and extracted by typing:

cd ..
rm ruby* -drf  

Installing Rails

Once Ruby Gems has installed, installing Rails becomes very easy. From the same terminal window type:

sudo gem install rails --include-dependencies

Wait for the Rails software to download and install, then close the terminal window.

Installing Lighttpd

To install lighttpd, we will return to YUM Extender. Make sure you are on the Install screen, and in the Filter textbox, type lighttpd. Now select the following packages:

Once you have selected these packages, click the Install button at the bottom of the Yum Extender window, follow the prompts and wait for the packages to download and install, then we will move on to the next step.

Installing mySQL

To install mySQL, we will stay in YUM Extender. Once again, make sure you are on the Install screen, and in the Filter textbox, type mysql. Now select the following packages:

Once you have selected these packages, click the Install button at the bottom of the Yum Extender window, follow the prompts and wait for the packages to download and install, then we will move on to the next step.

Configuring mySQL

Next we need to make a small configuration tweak to mySQL. It appears as though there is a problem between Rails (or the Ruby mySQL bindings) that makes the password storage method in mySQL 4.1 incompatible. To fix this we will edit the file /etc/my.cnf. Open a terminal window and type:

sudo gedit /etc/my.cnf

Now change the line that reads:

old_password=1

to:

old_password=0

Click te Save icon on the toolbar, then close the editor window.

Installing FastCGI Development Libraries

Now we need to install the FastCGI Development Libraries. These are required by Ruby-Fastcgi Bindings that will be installed in the next step. To install the FastCGI Development Libraries, we'll need to go back to a Terminal window and type the following commands (pressing enter at the end of each line):

wget http://www.fastcgi.com/dist/fcgi.tar.gz
tar zxvf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure
make
sudo make install

Wait for the compilation to finish, then cleanup the files we downloaded and extracted by typing:

cd ..
rm fcgi* -drf  

Now close the terminal window.

Installing Ruby FastCGI Bindings

Now we need to install the Ruby-Fastcgi Bindings. To install the Ruby-Fastcgi Bindings, we'll need to go back to a Terminal window and type the following commands (pressing enter at the end of each line):

wget http://sugi.nemui.org/pub/ruby/fcgi/ruby-fcgi-0.8.6.tar.gz
tar zxvf ruby-fcgi-0.8.6.tar.gz
cd ruby-fcgi-0.8.6
ruby install.rb config
ruby install.rb setup
sudo ruby install.rb install

If all goes well, you should see a message that says install done, then cleanup the files we downloaded and extracted by typing:

cd ..
rm ruby-fcgi* -drf  

Now close the terminal window.

And that concludes the installation of software required to get our server up and running!

Starting the lighttpd and mySQL Daemeons (services)

Now that all our software is installed, let run our servers and configure them to start with each reboot or restart of our FC4 system. To do this, we need to click on the Desktop menu located across the top of your FC4 desktop. Next choose System Settings, then choose Server Settings, ten choose Services. You will be asked for your root password, so type it in then click OK.

Now you should see the Service Configuration window. Along the left pane, you will see a list of all programs that can be started as or are currently running as a service. Scroll down the list until you see lighttpd. Place a checkmark next to it then click on the Start toolbar button. You should see a message that says lighttpd start succesful.

Now lets do the same for mySQL. Scroll down the list until you see mysql. Place a checkmark next to it then click on the Start toolbar button. You should see a message that says mysql start succesful.

Now both the lighttpd and mysql servers have been started, but we also want them to start automatically each time we start FC4. This is accomplished by clicking on the Save button in the toolbar!

Testing Lighttpd

Our next step is to make sure that Lighttpd is running. To test this, simply open the Firefox web browser by clicking on the Applications menu, choosing Internet then clicking on Firefox Web Browser.

Once Firefox opens, type http://localhost into the address bar then click enter. If the server is running you will see a webpage that says lighttpd - Lightning fast, light system requirements.

Securing mySQL

The first step to securing your mysql server is to set a root password. By default, when you install mysql, a root user account is created with a blank password. This is obviously a huge security hole and should be fixed immediately. To set a new password for the root account, open a new terminal window and start the mySQL client by typing:

mysql -u root -p

You will be prompted for a password, and as the password is currently empty, simply press the enter key.

Now lets change the password by typing the following command and replacing newPassword with a new password of your choice:

SET PASSWORD FOR root@localhost=PASSWORD('newPassword');

You will be prompted to enter a password. This password it is asking for is your old password, which by default is blank, so simply press enter and your new password will be applied to your account. Next, exit the mySQL client by typing:

exit

Now let's test you new password by logging into your mysql client by typing into a terminal window:

mysql -u root -p

You will be prompted for a password, type in your new password. You should now be logged into your mysql server.

Now lets delete some user account that have no username and/or no passwords. These are insecure accounts and should be deleted. In the same terminal window, type the following commands:

use mysql;
delete from user where user='';
delete from user where host='localhost.localdomain';

Now type exit to leave the mysql program.

Your mysql server is now as secure as your password.

 

Looking for a more permanent Rails hosting solution?

Dreamhost offers great Rails hosting packages. Signup now and enter the promotion code dmmrails to recieve $70 of your first year of hosting. Your total cost for one year will be $49 - that's only about $4 per month!
Signup Now!

Install Miscellaneous Software

The next step is to install 3 pieces of software that will help with you Linux development experience. The three items to install listed below will not be used in this how-to, but when you begin to develop your first Rails application, these tools will be very useful.

Bluefish Web Development Environment

There are a few Web Development packages available for Linux. For example you may have noticed that Eclipse is available as an option when you install FC4. Although Eclipse is an excellent development environment for Java and Web Application projects, it is really a big and complex program and probably more than we need for this tutorial. If you are familiar with Eclipse, please by all means go ahead and install it, but for this tutorial I am going to use the BlueFish HTML Editor. It is a capable but simple editor, but the main thing that drew me to it is the fact that it supports Ruby syntax highlighting! So lets install it.

To install BlueFish, we will need to start YUM Extender. Once again, make sure you are on the Install screen, and in the Filter textbox, type bluefish. Now select the following package:

Once you have selected this package, click the Install button at the bottom of the Yum Extender window, follow the prompts and wait for the package to download and install, then we will move on to the next step.

MySQL Query Browser

The MySQL Query Browser is the official GUI developed by the fine people who brought you the popular MySQL family of database products. MySQL Query Browser is an awesome piece of software that will allow you to manage your databases and tables through a very complete GUI. MySQL Query Browser is available for Windows, Mac OSX and Linux. We will of course, install the Linux version.

Start by opening a new terminal window and type the following command.

wget http://mysql.mirror.cygnal.ca/Downloads/MySQLAdministrationSuite/mysql-query-browser-1.1.12-linux.tar.gz

Next, we install the program by untaring the downloaded file by typing:

tar zxvf mysql-query-browser-1.1.12-linux.tar.gz

This is not really an installation but rather a simple extraction of the MySQL Query Browser files. What we need to do now is to create Launcher item to this program. You can start by closing all open windows, then right mouse click on your Linux desktop. A popup menu will appear and you will need to click on the item that says Create Launcher. The Create Launcher dialog box will appear. In the Name field, enter MySQL Query Browser. Next to the Command drop down list, click on the Browse... button. A Browse dialog will open where you should by default be placed in your home folder (if not, click the Home button at the top of the dialog). Look for a folder named mysql-query-browser and double-click on it to open. Now double click on the folder named bin. Next click on the file mysql-query-browser then click the Open button. Next you need to choose an icon for the Launcher item. Click on the square shaped button that says No Icon and choose an icon, then click the OK button.

Microsoft True Type Fonts

Fedora Core and other Linux distributions come without Microsoft True Type Fonts such as Arial, Verdana, Tahoma and Times New Roman. As these fonts are used by most web developers, you'll probably want to install these on your FC4 installation. You can follow the instructions provided by Mauriat Miranda in his guide - Install Microsoft True Type Web Fonts. I would write the instructions here, but Mauriat has provide a simple RPM package that includes the fonts and system settings.

Configuring Lighttpd

Alright, were done installing software, so lets begin to test our first Rails application. The goal here is to create a very simple Rails application to make sure everything with our installation is correct. Our first step is to modify our lighttpd configuration file, but before we do, lets backup the one that came with our installation (you may want to look at this one later, as it is much more complete than the one provided here). To backup the old configuration file we're going to move it to a new file, so open a terminal window and type:

cd /etc/lighttpd
sudo mv lighttpd.conf lighttpd.conf.old

Now we'll create new lighttpd configuration file by typing:

sudo gedit lighttpd.conf

An empty GEdit window will appear. Copy the text below into this new editor window and change every instance of yourHomeDir to your system user name. Click the save button and close GEdit.

server.port = 80
server.pid-file = "/tmp/test_lighttpd.pid"

server.modules = ( "mod_redirect", "mod_access", "mod_fastcgi", "mod_accesslog", "mod_simple_vhost" )

server.document-root = "/srv/www/lighttpd/"
server.indexfiles = ( "index.php", "index.html" )
accesslog.filename = "/var/log/lighttpd/access_log"
server.errorlog = "/var/log/lighttpd/error_log"

# simple virtual hosting
simple-vhost.server-root = "/home/yourHomeDir/"
simple-vhost.default-host = "test"
simple-vhost.document-root = "public"

# Start of test vhost
$HTTP["host"] == "test" {
  server.document-root = "/home/yourHomeDir/test/public/"
  accesslog.filename = "/home/yourHomeDir/test/log/access.log"
  server.indexfiles = ( "dispatch.fcgi", "index.html" )
  server.error-handler-404 = "/dispatch.fcgi"

  # rails stuff
  #### fastcgi module
  fastcgi.server = (
    ".fcgi" => (
      "test" => (
        "socket" => "/tmp/test1.socket",
        "bin-path" => "/home/yourHomeDir/test/public/dispatch.fcgi",
        "min-procs" => 1,
        "max_procs" => 2
      )
    )
  )
}
# End of test vhost

# mimetype mapping
mimetype.assign = (
".rpm" => "application/x-rpm",
".pdf" => "application/pdf",
".sig" => "application/pgp-signature",
".spl" => "application/futuresplash",
".class" => "application/octet-stream",
".ps" => "application/postscript",
".torrent" => "application/x-bittorrent",
".dvi" => "application/x-dvi",
".gz" => "application/x-gzip",
".pac" => "application/x-ns-proxy-autoconfig",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".tar" => "application/x-tar",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".ogg" => "audio/x-wav",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".xbm" => "image/x-xbitmap",
".xpm" => "image/x-xpixmap",
".xwd" => "image/x-xwindowdump",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".asc" => "text/plain",
".c" => "text/plain",
".conf" => "text/plain",
".text" => "text/plain",
".txt" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".mov" => "video/quicktime",
".qt" => "video/quicktime",
".avi" => "video/x-msvideo",
".asf" => "video/x-ms-asf",
".asx" => "video/x-ms-asf",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar"
)

Once again, make sure you change every instance of yourHomeDir to your system username.

What we've done here is to configure lighttpd to use virtual hosts. Virutal host uses the Simple Virtual Host module as defined in the server.modules section. The advantage of using virtual hosts, is that we can simply add addional vhost sections to our lighttpd.conf file to run different Rails applications. For more information on virtual hosts and lighttpd, see the lighttpd documentation website.

The host name we have configured lighttpd to use is test, but before we can access that host, we need to add an entry to our hosts file. The hosts file, is a simple text file that Linux checks before it does and Domain Name Lookup. If it finds the host in this file, it resolves it to the IP address specified for that host. So lets edit the hosts file by opeing a terminal window and typing:

sudo gedit /etc/hosts

Then add the following line to the end of the file:

127.0.0.1     test

Save the file and close the GEdit window.

Finally lets restart our lighttpd server so that our changes to the configuration file are reloaded. To do this, we need to click on the Desktop menu located across the top of your FC4 desktop. Next choose System Settings, then choose Server Settings, ten choose Services. You will be asked for your root password, so type it in then click OK. Now click on the service named lighttpd and then click on the Restart toolbar button. Check to make sure that the server starts properly, and if not, double check the accuracy of the lighttpd.conf file.

Creating a Test Rails Application

To create our test Rails application, we need to perform the following tasks:

If you're not familiar with Rails, the terms model and scaffold probably don't mean much to you, but don't worry, follow along with the next few steps then be sure to read the articles that I link to at the end of this how-to. They will orient you with the lay of the land when it comes to Rails development.

Lets start by creating the database. Open a terminal window and login to our MySQL client by typing:

mysql -u root -p

You will be prompted for a password, type in your password and press enter. You should now be logged into your mysql server. Now type the following commands into the MySQL client:

CREATE DATABASE contacts;
USE contacts;

CREATE TABLE contacts (
id int(10) unsigned NOT NULL auto_increment,
name varchar(50) NOT NULL default '',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO contacts VALUES (1,'Jim Rutherford');
INSERT INTO contacts VALUES (2,'Robert Blawbla');

exit

Next we're going to Create the Rails application, but before we issue the rails command, we need to make sure we're in our home directory so in your teminal window type:

cd /home/yourUserName

substituting yourUserName with your system user name. Next create your Rails application by typing:

rails test

Next we need to set file permissions on the rails log and public folder

cd test
sudo chmod -R 775 log
sudo chmod -R 775 public

Using the BlueFish web editor, we are going to edit the database.yml file that is located in /home/yourUsername/test/config folder. To start Bluefish, click on the Applications menu then choose Programming then click on the Bluefish item. Using the file navigation pane on the left side of the window, navigate to the /home/yourUsername/test/config folder then open the database.yml file by double-clicking on it. Now change the development section so that is reads:

development:
  adapter: mysql
  socket: /var/lib/mysql/mysql.sock
  database: contacts
  host: localhost
  username: root
  password: yourPassword

Now save the file and close it.

Next, open a new terminal window and type:

cd test

Now lets generate the model for our contacts table by typing:

script/generate model contact

Finally, we'll create the scaffold by typing:

script/generate scaffold contact

Scaffolding is really cool - in very brief terms, it creates listing, editing, deleting, and adding forms for your web application!

So now for the grand finale! Let's open our Firefox web browser and test our test application. In the Firefox location bar, type http://test/contacts. If all goes well, you will see a screen that lists the two names in our database along with some action links for editing, adding and deleting records.

Looking for a more permanent Rails hosting solution?

Dreamhost offers great Rails hosting packages. Signup now and enter the promotion code dmmrails to recieve $70 of your first year of hosting. Your total cost for one year will be $49 - that's only about $4 per month!
Signup Now!

Links

Here are some links to get you going with Rails development:

About

This how-to was created and will be maintained by Jim Rutherford. He is a web developer from Nanaimo, B.C. Canada. He can be contacted through email at jim.rutherford@gmail.com. Please send your comments and feedback and bug reports to this email address.

 

Last updated - 28-Jul-2005