PROGRAMMING/BIOINFORMATICS: Part II of a outline guide to setting a Mac OS X machine up for a web server database using Mac OS X 10.6.x, MySQL and Perl.
Originally intended as one long document, I have broken this into several parts to better suit my time. Part II focuses on installing the modules the Perl programming language requires in order to interact with the relational database, MySQL, and setting up the first (empty) database and where to place your WWW files and scripts. These instructions do not consider Mac OS X Server, which has a slightly different setup for MySQL. Part I covers installing MySQL.
I’m not going to get into the details of tweaking config files and whatnot – the aim here is to offer a basic recipe that should work for most people without too much extraneous fluff which confuse a first-time installs. It’s a prescriptive outline rather than an detailed explanation.
I’m going to assume installing it on a client’s machine, i.e. you’ve no idea what it’s set up with.
Installing perl database modules via CPAN
CPAN is the comprehensive perl archive network, basically a collection of more perl modules that you could believe existed. Although you can manually download the modules and install them, it’s easier to run CPAN from the command-line perl, especially if you already know what modules you want to install.
Start up CPAN via perl:
perl -MCPAN -e ‘shell’
You will almost certainly be invited to update CPAN.pm; if so, do that now. Generally it’s best to accept the offer to do the update automatically.
You may run into complaints about a lack of YAML. This appears to be a ’standard’ issue on Mac OS X. (Try ‘install YAML’ if it bothers you in the next step.)
Once you’ve updated CPAN.pm, quit, then re-enter this time with superuser status:
sudo perl -MCPAN -e ‘shell’
(You need superuser status or ‘make’ will fail.)
To install modules, type ‘install module-name’ at the CPAN shell prompt, for example:
Install the database modules, DBI first then DBD (DBI is needed for DBD to install):
That last step *may* give you some grief, as the testing portion of it requires access to a running MySQL (hence starting it in an earlier step and leaving it running). See footnote .
Preparing the MySQL database for use
First, shut down the running database if it’s running. Use the Preference Panel, it’s easier. (See first part of this series.)
Installing the first database into MySQL follows are particular series of steps; you can’t just jump in.
To set up the root password to ‘wthisapddh’ and create an empty database ‘first_db’ use:
cd /usr/local/mysql ./bin/mysqladmin – root password wthisapddh cd bin ./mysqladmin -u root -p create first_db
(Replace the password and database name with your own choices.)
You will be best to limit database names to alphabetic (or alphanumeric) characters and underscores in the interests of portability.
Now turn the database server back on.
Access the new database and set up ordinary (non root) access should you want this, e.g.
mysql -u root -p
You will be promoted for the database root user password. Now you can type in SQL commands to connect to the database and grant ordinary users access to it, identified by a password (‘badusrpwd’ in my example):
connect first-db grant all on *.* ‘dbuser’@'localhost’ identified by badusrpwd
Now user ‘dbuser’ can access the database either via the mysql command,
mysql -u dbuser -p
or via perl scripts owned by that user.
Installing web server files
The standard location for web pages and scripts for personal websites and services for Mac OS X systems is
and for ‘global’ web services
(You can in fact store them elsewhere, but unless you want to muck around with configuration files and file permissions (file access rights), go with the flow.)
You’ll note that the latter is subdivided into CGI-Executables, Documents and share.
Scripts (a.k.a. CGI files) must be executable. To make them executable in Terminal use,
chmod +x filename
In the next part of this series, we’ll look at configuring the web server.
These notes are–self-evidentally, I hope–only a sketch outline, but I hope that they serve the majority of users.
 If you get really stuck with the DBD install, first try manually searching search.cpan.org for BDB::MySQL, downloading the file, decompressing the file, enter the directory created then try manually build it, as per the instructions in the README file:
The first step generates a makefile, that the next three steps use. If you need to start over, use make clean to tidy up loose bits lying around before trying again.
If you are still stuck, you may find that using this in place of perl ./Makefile.PL helps:
perl ./Makefile.PL –testdb=test –testuser=test –testpassword=test –testhost=localhost
You’ll want the database to be up and running, of course, so that the testing code can access it.
If none of these work, you’re best to ask around.
Other articles on Code for Life: