The purpose of this exercise is to get a clean working environment for Ruby on Rails. Using any of the current web hosting control panels makes it a hack to put it lightly. Since I was going to do it from scratch to begin with, I reasoned that I should be using the best software for the job and not the most popular.
I am not going to go through the steps of actually installing FreeBSD, that has been explained all to well in other places. I will note that I did a basic install, that is to say that I did not elect to install any applications or ports.
To start things off, we will want to get a fresh copy of the ports installed on our boxen. We use to do this by setting up CVSup and getting the latest ports releases. With FreeBSD 6, we have a new utility that is installed by default called Portsnap. Portsnap is a system for securely downloading and updating a compressed snapshot of the FreeBSD ports tree, and using this compressed snapshot to extract or update an (uncompressed) copy of the ports tree. So lets go and get the latest ports and then extract them into our ports tree.
[server][root][~]# portsnap fetch
There we go, we have a shiny new compressed copy of the entire ports tree. Now lets create our directory structure and extract the snapshot.
[server][root][~]# mkdir /usr/ports;portsnap extract
A lot of items tend to rely on Berkeley DB from Sleepycat (now owned by Oracle), so lets get started with the latest version instead of an earlier version that some ports want to install by default.
[server][root][~]# cd /usr/ports/databases/db44;make install clean
Install portupgrade, which also includes the Portinstall utility that we will be using to install the rest of our ports. Installing portupgrade also installs Ruby as a dependency, which is cool because we will not have to deal with it as a separate item later on.
[server][root][~]# cd /usr/ports/sysutils/portupgrade;make install clean
Lets give out the ole’ rehash command so that csh will recognize the newly installed application. This little item will go away after we install the bash shell later on.
[server][root][~]# rehash
Now lets install portmanager, which we will use to upgrade our ports with. I used to use Portupgrade, but this seems to be a nicer solution to upgrading the ports and their dependencies. I guess time will tell on this one. I did not select any of the compile options.
[server][root][~]# portinstall portmanager
Another nifty item that I like is Portaudit, that I use to mitigate third party vulnerabilities (the ports). Portaudit polls a database, updated and maintained by the FreeBSD Security Team and ports developers, for known security issues. During the install process, Periodic(8) gets updated, so that daily security run emails get sent to root’s email account.
[server][root][~]# portinstall portaudit
Now that it installed, we need to update the database stored in /var/db/portaudit. The database will automatically be updated during the periodic(8) run, so this is optional.
[server][root][~]# rehash
To audit the few ports we have installed at this point, we can run the following command
[server][root][~]# portaudit -a
If there are problems then you will have some output and then you can use portupgrade to upgrade the affected package.
Now that we have the ports system taken care of, lets configure a way to get the base system updated. To do that we will use freebsd-update to download and install binary updates to the base system.
[server][root][~]# portinstall freebsd-update
[server][root][~]# cp /usr/local/etc/freebsd-update.conf.sample /usr/local/etc/freebsd-update.conf
[server][root][~]# rehash
[server][root][~]# freebsd-update fetch
If there were any updates downloaded then we could use the following to install them.
[server][root][~]# freebsd-update install
Now for some usability items that I have grown fond of while using Linux over the past few years.
I mentioned earlier that I prefer the bash shell compared to csh, so lets get that installed. When installing bash, you will have some choices to make. I like bash2 and have no need for bash1, so when asked about bash2, type yes and type no when asked if you want to install bash.
[server][root][~]# portinstall bash
If you have edited anything on the system yet with vi, then you will notice how bare it is compared to vim (no, before you ask, I do not use Emacs). Lets install vim without the X Window options that get installed with the regular vim port.
[server][root][~]# portinstall vim-lite
Now when I look at directories using ls, I like the directories and files to be shown in all their glorified color, so I can quickly see what is going on. I prefer GNU ls instead of the default FreeBSD ls, so lets install gnuls.
[server][root][~]# portinstall gnuls
Lets go ahead and setup our locale in /etc/login.conf. Make sure the end of your default section looks like the following, paying special attention to put a backslash (\) at the end of the umask line.
:umask=022:\
:charset=en_US.UTF-8:\
:lang=en_US.UTF-8:
Save and close the file.
We need to rebuild the login.conf database for our changes to take place.
[server][root][~]# cap_mkdb /etc/login.conf
I guess that is all for now. In the next post on the subject, I will do a little house keeping and setting up dot files to make bash, vim, and gnuls a bit more user friendly.
Rails Server Setup:
Part 1: New Server Setup
Part 2: Setup FreeBSD 6.x
Part 3: FreeBSD Usability
Part 4: Setup FreeBSD To Use Blowfish
Part 5: Install and Setup PostgreSQL
Part 6: Install Lighttpd on FreeBSD
Part 7: Install MySQL 5.x on FreeBSD
Part 8: Install Ruby On Rails with FreeBSD