1. Developing on OS X, pt. 2

    March 27, 2006

    This article relates to installing and working with Apache, PHP and MySQL in OS X 10.4. These instructions may be out of date on later versions of OS X.

    The first part of this tutorial focused on getting Apache up and running in a way that would hopefully reflect a live server environment. This second part will explain how to get PHP and MySQL, the most popular server side language and database combination, installed on your local machine.

    Installing PHP

    Many old-schoolers would download the latest source from php.net, compile it for their machines with custom modules and install it straight to Apache in OS X. As you may have guessed, this is not my way, instead I prefer to get pre-compiled packages from Marc Liyanage that can be installed into Apache like you would any other OS X package. He has all of the latest flavours available—I use PHP 5 locally to reflect my online environment. Using Marc's excellent packages, you don't need to delve into the httpd.conf file to register file extensions or any other dirty work.

    Update: I've just upgraded my work system using the latest version of Marc's PHP packages and short tags—the preferred method of echoing data in frameworks like CodeIgniter—are not enabled by default. To enable them you need set short_open_tag = On in the php.ini file, located in usr/local/php5/lib/. The value you need to change should be around line 141 and should be changed to the above. This allows you to use <?= ?> tags in your code.

    Installing MySQL

    Since version 4.0.11, Marc's packages have been superseded by similar packages direct from MySQL—these are exactly the same in that they allow you to install the MySQL database from a one-click package file, and they also helpfully add a system preferences button to give you a bit more control and allow you to run the database at start-up and restart the MySQL server.

    Administering MySQL Users & Databases

    As well as the self-installing package, MySQL have released a number of useful tools that make running MySQL a much simpler, and less command-line driven, task.

    The first of these tools is MySQL Administrator—an application that allows you to add and remove users and database schemas. This is the easiest way to maintain your user accounts on the local database and carry out simple database design tasks. I always change my root password from here as it takes far less time than going through the terminal.

    The second tool I use extensively is MySQL Query Browser, also from MySQL. This application revolves around database design and allows you to create databases, (called Schemas), stored procedures, (if you use MySQL 5) and add/edit/delete data from your databases. This was the main method of designing and altering the CheckWithMother databases during development. I should warn you that MySQL Query Browser does suffer from sporadic quitting problems—this is being worked on by the developers but can be quite annoying.

    Another advantage of both of these tools is that they allow you to access external databases if your hosting company allows it—this is very useful as I can modify data on a live database if such a need arises.

    There are other tools of note that can be used to play with MySQL—in the past I have used both CocoaSql and YourSql, but neither support stored procedures in MySQL 5 so became less useful when Dreamhost upgraded their versions.

    That's it! You should now be able to run local domains, administer your databases and run PHP-driven sites all form your local machine. Now lets hope someone makes it just as easy to install and deploy [Ruby on Rails] locally.

  2. Developing on OS X, pt. 1

    March 19, 2006

    This article relates to installing and working with Apache, PHP and MySQL in OS X 10.4. These instructions may be out of date on later versions of OS X.

    Mac OS X comes pre-installed with possibly the most popular, secure and easy to use web server available to the modern web developer, but it does take some tweaking to get it working as a suitable testbed and prototyping environment before you move our applications over to your live servers.

    Where To Store Your Documents

    The first step in setting up your server is working out what you need to host, where to put the files in Finder and how to see it in your web browser. Apache serves its documents from /Library/Webserver/Documents/ and this is the best place to store your files. If, like me, you use various hosting companies, you'll probably want to organise your files further—I tend to reflect my set up on the live server in my development server so it looks nice and organised in Transmit.

    Setting Up Nicer Local URLs

    Once you have created your folder structure and moved your files, go to in your browser and you should see your folder structure reflected through Apache. This is nice, but in order to view your local projects you will probably end up with long, ugly and possibly broken URLs. This can be fixed by setting up ‘host names'—local URLs you add only to your machine so you can use addressing conventions more in line with those in your live environment. To add or modify these host names, you'll need to do the dirty and open the Apache configuration file—the httpd.conf file. I recommend using [Textmate], (for all text-editing, not just this), in which case you need to select 'View hidden files’ in the open dialogue to get at the configuration file. It is located in /etc/httpd/.

    In the file, (around line 1060) there is an option preceded by a hash, 'Name VirtualHost *:80'. Remove the hash to enable this option, (hashes are comments you know). You then need to add a virtual name host for each of the URLs you wish to set up, as well as a default entry for localhost, the root of your Apache server, (located at

    # Default for - it makes sure that localhost works.
    <VirtualHost *:80>
      DocumentRoot /Library/WebServer/Documents/
      ServerName localhost
    # Add new hosts here for development
    <VirtualHost *:80>
      DocumentRoot /Library/WebServer/Documents/dreamhost/beseku.com/v9/
      ServerName www.beseku.dev

    The code above creates two virtual name hosts—the first is the default entry pointing at http://localhost and the second is for http://www.beseku.dev, a development version of this very site. The first parameter is the physical location of the directory and the second is the URL you wish to use. Take care when adding addresses that you don't use a URL currently in use on the web—your machine will always go to your files instead and you won't be able to view the site!

    Setting Up Nicer Local URLs: Netinfo Manager

    That isn't quite it for the local addresses, you have told Apache where to find the files for that URL but you also need to tell OS X that the address is a local one. Open Netinfo Manager, (Applications/Utilitites) and select the ‘machines' option in the second column. This will list a number of hosts your Mac uses to reference the web server. Duplicate 'Localhost’ and replace the name value in your duplicate with that of the host you created in Apache. Save this when prompted and restart personal web sharing. You should now have a test URL set up pointing to your development files.

    Using .htaccess

    Its very Web 2.0, (don't), to have nice tidy addresses without ugly query strings in the URL. To accomplish this, you will need to make use of the .htaccess file—a kind of local configuration file for the current folder. I won't tutor on the .htaccess file because I am no expert. The reason I mention them is because in Mac OS they are disabled by default. To enable them, you will need to once again open the httpd.conf file and alter another option.

    # This controls which options the .htaccess files in directories can
    # override. Can also be "All", or any combination of "Options", "FileInfo",
    # "AuthConfig", and "Limit"
    AllowOverride None

    You need to change this to the following to enable .htaccess files on your web-server.

    # This controls which options the .htaccess files in directories can
    # override. Can also be "All", or any combination of "Options", "FileInfo",
    # "AuthConfig", and "Limit"
    AllowOverride All

    Save the file and you should now have access to all the .htaccess voodoo you want. Roberts your father's brother, you've set up Apache to work like it should!

    The second part of this tutorial will focus on getting the latest versions of PHP and MySql installed on your machine and introduce some nifty tools you can use to make it all a bit easier to play with, (and help you to avoid the terminal).

  3. Simply applying ‘hasLayout’

    March 5, 2006

    If you need to apply the hasLayout property to an element in Internet Explorer but don''t want to add height or another potentially damaging CSS property, use the proprietry zoom:1;. It is an IE only CSS property and sets the hasLayout flag to true while adding nothing visually or semantically to the element. Saved my skin more times than I care to remember.