Database backed web applications: software selection

FreeBSD is billed as a server platform, and I select it for this application, so that's the operating system this is going to run on. As a server platform, setting up an 3-tier application with a web server as the middle level and a database as the back-end server should be painless. I'm happy to report that an afternoon spent setting up the sample application - a dynamically sorted list of links - along those lines was indeed painless.

Selecting the software

Three pieces of software need to be selected, and possibly some way to interconnect them. Those are:

A database
FreeBSD provides an excellent selection of open source databases. Three popular ones - PostGreSQL, MySQL and mini SQL - are all available in /usr/ports. Others - such as Solid and Oracle - are available from the vendors, possibly running under the Linux emulation code. I chose PostGreSQL because of the three in the ports collection, it was the one that supported transactions, which I feel is a requirement for reliable database applications.
A web server
Again, a wide selections is available in /usr/ports. Various versions of Apache, as well as wn, boa, and xitami are all there. Other web servers targeted for Unix platforms are available from the vendors. Apache is a high-performance general-purpose web server. It provides many configuration options, at both compile time and at server startup. It also has a large selection of modules, that are liable to be useful given the test bed nature of the installation I am building.
A development language

The performance of code in the language is not a critical issue - most of the work is going to be parsing HTTP requests, and reformatting database query results into HTML. The performance issue here is that the string-handling facilities be fast. If these are well written, performance may actually exceed hand-coded C or assembler that does things in an obvious way, because the library found a non-obvious but faster solution. This allows much freedom in the language choice.

FreeBSD adds to that, as it has a large selection of languages. The ports tree has 90 subdirectories in its languages directory, though that includes multiple versions and multiple distributions sets of some of the languages. I chose Python because I wanted a dynamic language that was designed with OO features in mind. This example doesn't make particularly good use of those features, but I did want them.

These three parts of the system were trivial to install. As root on the system, the following commands did the trick:

# cd /usr/ports/www/apache13
# make install
# cd /usr/ports/databases/postgresql
# make install
# cd /usr/ports/lang/python
# make install

After you've installed the packages, you can start the servers running by invoking (as root) the shell scripts each installed in the /usr/local/etc/rc.d:

# /usr/local/etc/rc.d/pgsql.sh
# /usr/local/etc/rc.d/apache.sh

The last piece was the connection between Python and the PostGreSQL database, that can also be found in the ports tree. Thanks to FreeBSD's support of shared libraries - and Python's use of them - no changes to any of the previously installed software needs to be made. Just:

# cd /usr/ports/databases/py-PyGreSQL
# make install

and everything I needed to build my 3-tier application was installed and ready to use. The next step is to define what the application does.


Prev, Next, Contents

Mike Meyer,
March, 1999