Now that we’ve dealt with some basic user and directory management, it is time to get cracking and fill our delicious VM with quality web development software. First of all, however, we need to setup networking in order to access the internet. Our VM has been configured to use bridged networking - I’m working on the assumption that you get online via a broadband router (be it ADSL or cable) and that said router is capable of mapping ports between your external interface and your internal network interfaces. Personally, I use a D-Link cable router which, despite its shonky web admin suite, is pretty darn reliable and easy to maintain.
FreeBSD’s configuration utility is called sysinstall, which we will use in order to configure networking. Interaction is controlled via your keyboard - as with Windows, TAB will cycle through available fields and buttons. On with the show!
- Log into your VM as ‘root‘
- Type ‘
sysinstall‘ and hit Enter to fire up the configuration utility
- Select ‘Configure‘, then ‘Networking‘, and then ‘Interfaces‘
- Select “le0” from the adapter list
- When prompted if you want to configure IPV6, highlight ‘NO‘ and hit Enter
- When prompted if you want to configure DHCP, highlight ‘YES‘ and hit Enter
- FreeBSD will poll for an available DHCP server. If it is successful, enter a suitable hostname and domain in the relevant fields (they don’t have to resolve externally), then select ‘OK‘ and hit Enter
- Choose ‘Exit‘ twice and then finally ‘Exit Install‘
- To test your changes, try pinging Google!
If the test works, give yourself a small pat on the back and go make a cuppa. If it doesn’t or you don’t have the requisite hardware configuration, don’t panic! You can shutdown your VM with the command ‘shutdown -h now‘ and change the networking type to NAT. Go through the same procedure as before, searching for an available DHCP server (which VMware emulates) and setting up your hostname and domain information. The only drawback is that port forwarding won’t be as easy, if your intention is to allow testers/friends to try out your funky web applications over the web. I will attempt to cover this alternative setup method at a later date, so don’t feel left out! Stay tuned and I promise I’ll get you sorted!
Okay, those of you with cuppas should settle back down again and prepare to retrieve and install the latest build of the FreeBSD ports collection. Ports are installed via source tarballs, which are downloaded automatically from the internet when you invoke a port’s build command. For those of you familiar with C compilation, you will probably recognise some of the terminology used below.
Firstly, we want to grab the latest ports collection. Portsnap is just the command for the job - it is installed by default, so you won’t end up in a paradoxical situation like users of FreeBSD 6 or earlier who had to somehow install portsnap via the ports collection, despite the fact that they hadn’t yet installed their ports collection..
- Type ‘
portsnap fetch extract‘ and hit Enter
If I were you, I’d either go and grab a few biscuits to go with that cuppa (if you haven’t drank it all, that is) as the fetching and extraction process takes about 10 minutes. You can sit and watch it run it’s course if you really want to, but you will be treated to a monochrome poor man’s equivalent of the Matrix without the reference to spoons or white rabbits.. I recommend that you do something more interesting instead!
To install a port for the first time, you need to move into the port’s directory and build it by invoking the ‘make‘ command. Before we install any web development ports, we want to install one that will make our collective lives easier regarding port maintenance. Enter ‘portmanager’…
- Type ‘
cd /usr/ports/ports-mgmt/portmanager‘ and hit Enter
- Type ‘
make install clean‘ and hit Enter
- When the configuration screen appears, accept the defaults, select ‘OK‘ and hit Enter
- Once installed, log out of your VM and then log back in - FreeBSD pathing means that you won’t actually be able to see the portmanager binary until you do so (if anyone knows a more efficient way to do this, please let me know!)
- After you log back in, type ‘
portmanager -ui -u‘ and hit Enter - this will run portmanager in interactive mode using the default bundled configuration options
- A list of installed ports will slowly scroll down your screen, afterwhich you will be presented with your first update prompt
- Press ‘Y‘ to update each port in turn or press ‘A‘ to update all out-of-date ports
- Accept defaults when prompted at any configuration screens
Excellent work! Your installed ports are now all up-to-date! Next up, we need to install a decent text editor for our local configuration changes. Many people swear by VI/VIM but I prefer Nano - a cute redux of Pico, which came bundled with the archaic Pine UNIX mail client. Nano is really easy to use and even easier to build using the ports collection.
- Type ‘
cd /usr/ports/editors/nano‘ and hit Enter
- Type ‘
make install clean‘ and hit Enter
- Log out of your VM and log back in
Next up, we want to go ahead and setup Apache. The 2.2 branch is stable and perfect for our needs.
- Type ‘
cd /usr/ports/www/apache22/‘ and hit Enter
- Type ‘
make install clean‘ and hit Enter
- On the configuration screen, select ‘BDB‘, then highlight ‘OK‘ and hit Enter
PHP5 is next on the list! You see how easy this is?
- Type ‘
cd /usr/ports/lang/php5/‘ and hit Enter
- Type ‘
make install clean‘ and hit Enter
- On the port’s configuration screen, make sure the APACHE option is selected - we want to build PHP5 as a Apache module. Highlight ‘OK‘ and hit Enter
You may have noticed that only the standard PHP5 extensions were installed. That is because the rest of them are stored in a handy meta-port, meaning we can add and remove extensions as and when we need to.
- Type ‘
cd /usr/ports/lang/php5-extensions/‘ and hit Enter
- Type ‘
make install clean‘ and hit Enter
- On the port configuration screen, select the following extensions:
- ctype, curl, dom, filter, ftp, hash, iconv, json, mysql, mysqli, pcre, pdo, pdo_sqlite, posix, pspell, session, simplexml, soap, sockets, spl, sqlite, tidy, tokenizer, xml, xmlreader, xmlwriter, zip, zlib
- Highlight ‘OK‘ and hit Enter
As you have selected the mysql extension, port dependencies will kick in and automatically install the MySQL 5.0 client plus library files - handy! The whole PHP extension installation process will take a while so be patient!
As we have installed the client, it would make sense to install the matching server port!
- Type ‘
cd /usr/ports/databases/mysql50-server/‘ and hit Enter
- Type ‘
make install clean‘ and hit Enter
If you’ve made it this far, then you’re doing great. You have installed the latest ports collection; you have updated your installed ports to the latest version; and you have successfully installed PHP5, Apache 2.2, MySQL 5.0 and a humble text editor called Nano. In my next post, I will show you how to configure each one in turn and add them to your VM’s startup procedure. TTFN!