If you've read the first three articles in the series, you are well on the way to getting an embedded development server up and running. You've got the hardware, burned it in, installed a basic FreeBSD system, and are now able to SSH into an account on the server.
In this article, we'll learn about the very cool ports collection for FreeBSD. We'll see how easy it is to build applications from source and have them installed automatically.
Instead of actually using the standard ports method of building an application for your FreeBSD box, we're going to take a slightly more complicated route and save quite a bit of disk space in the process.
Note that the technique for building a port without the ports collection is drawn from Dru Lavigne's excellent FreeBSD Hacks book. The specific hack we're using as the basis for this article is available online at O'Reilly.com.
The perl that comes with FreeBSD is back at 5.006, while many of the more capable packages require perl 5.6 or higher. After we get perl built and installed, we'll get postfix and Apache 2 running. This will give us the ability to serve up web pages and execute CGI scripts, which are the doorway to our bugtracker.
Before you get too far ahead of things, it's worth reading this overview of the FreeBSD Ports Collection.
Then you may want to browse around and look at some of the ports that are currently available.
There are a number of articles on FreeBSD ports, including this one that goes into a bit more detail on building and installing software, and another one on some useful tools for maintaining your ports tree.
Installing a port using just barebones cvs is pretty simple, as long as you have a handle on what the ports tree actually does. Basically, it's a way of grouping applications that you might want to build into categories. Each application has a series of files that describe exactly how to build the application. Often there are dependencies on other libraries or applications, but these dependencies can be difficult to extract automatically.
Remember to log into the root account on your server to build a port!
The first thing to do is to figure out if there's a cvs server near you that will accept pserver connections. The list of servers in the Anonymous cvs section of the FreeBSD Handbook that accepts pserver connections is:
Austria: :pserver:anoncvs@anoncvs.at.FreeBSD.org:/home/ncvs
France: :pserver:anoncvs@anoncvs.fr.FreeBSD.org:/home/ncvs
Germany: :pserver:anoncvs@anoncvs.de.FreeBSD.org:/home/ncvs
Germany: :pserver:anoncvs@anoncvs2.de.FreeBSD.org:/home/ncvs
Japan: :pserver:anoncvs@anoncvs.jp.FreeBSD.org:/home/ncvs
All of these servers will accept "anoncvs" as the password after you login to the server. To establish a cvs session with one of these servers, do the following:
setenv CVSROOT :pserver:anoncvs@anoncvs.fr.FreeBSD.org:/home/ncvs cvs login
When prompted, enter the password and you're ready to grab source code and start building your port. When you're done, remember to explicitly log off from the server, like this:
cvs logout
Files fetched from a cvs server go into the current directory, so you want to make sure you're in the right place before issuing any cvs commands. Also, the cvs command line options have to be carefully set up, or you'll end up getting the wrong code from the repository.
First, let's understand exactly what the FreeBSD cvs archive is. You can use the cvsweb interface to browse all of the source code that makes up the FreeBSD system. We're only interested in the "ports" section here, so click on "ports" or the folder icon next to it to drill down one more level.
Scroll down to the bottom of the page, and you'll see a drop-down box that lets you pick the exact revision of the ports tree you're interested in. Click on the drop-down box to see all the available tags.
We've installed FreeBSD 4.10 on our server, so the tag we're interested in is RELEASE_4_10_0. Remember to specify this tag any time you're pulling code out of the ports tree using cvs, otherwise you'll get the most recent source which is for the 5.2 release!
When cvs pulls the code out of the repository, it puts it in the current directory. This means that if you get something called ports/INDEX from the server it will be put into ./ports/INDEX on your machine. The ports system usually lives in /usr/ports, so make sure your current working directory is /usr when you're extracting ports from the cvs server.
Let's get started and retreive the files that provide the core ports functionality.
setenv CVSROOT :pserver:anoncvs@anoncvs.fr.FreeBSD.org:/home/ncvs cd /usr cvs login cvs checkout -A -P -r RELEASE_4_10_0 ports/Mk cvs checkout -A -P -r RELEASE_4_10_0 ports/Templates cvs checkout -A -P -r RELEASE_4_10_0 ports/Tools cvs checkout -A -P -r RELEASE_4_10_0 ports/INDEX cvs logout
This will populate /usr/ports with the files you must have for the ports system to work correctly. Next, we'll install perl, which will require a little bit more fancy footwork to get running, but the result is well worth it.
Installing perl from source using cvs requires a bit more detective work. Once you get the hang of it, the process of installing other ports from source is much simpler. The trick is in figuring out exactly what other libraries and programs the port you are trying to install depends on. Once you know that, it's pretty straightforward.
So, how exactly do we figure out what we need to build perl from source? Head on over to the FreeBsd Ports page and click on "lang" which gets you a list of about 300 different programming languages you can install on your server.
Have a close look at the Requires line of the port you want to install. For perl-5.8.2 there are no required libraries or applications so we should be able to just grab the source and build perl.
Click on the title line of the port (perl-5.8.2 5) and it will take you right to the web interface of cvs for that port. The top of the page will tell you exactly where to get the source for the port, which in this case is ports/lang/perl5.8, so let's do it:
cd /usr cvs login cvs checkout -A -P -r RELEASE_4_10_0 ports/lang/perl5.8 cvs logout
Now you're ready to build your shiny new version of perl! Just type the following lines (still logged in as root):
cd /usr/ports/lang/perl5.8 make install
Once the blur of activity stops, the following message will appear, I've copied it here for reference in case you've already lost it...
Installation of Perl distribution is finished. Please note, that since Perl is also in the base system, this distribution will not be used by default. If you want this version of Perl to be used by default, please type use.perl port Assuming that use.perl script (which was installed with the rest of the Perl distribution) can be found in your PATH (you might have to type `rehash' first, depending upon a shell you use), this action will replace /usr/bin/perl and /usr/bin/suidperl with symbolic links to the versions of these binaries in the Perl distribution. This action will also put some variables into your /etc/make.conf file, so that newly installed ports (not packages!) will use new version of perl, and the system upgrades from the source will not overwrite the changes made. At any time you can also type use.perl system if you wish to revert back to the system version of perl.
It's a good idea to get in the habit of reading and following instructions before you make changes willy-nilly. The following lines will check the existing version of perl, rehash the PATH, install the new perl, and then verify that the new perl is actually being used.
perl -v rehash use.perl port perl -v
This proves that you have upgraded from perl 5.005_03 to perl 5.8.4, and you're ready to tackle installing more ports.
If disk space is an issue, you can run
make clean
to get rid of all the source and object files resulting from the installation of perl. I've got plenty of disk space, and might even be doing this on another server, so keeping one copy of the current build around might save some time down the road.
That's all for now. Next time, we'll cover the installation of a secure and easy to administer mail system called postfix.