You are currently browsing the archives for the Mac OS category


Tidy up your XML

When I’m doing web services development I get frustrated trying to read through a gob of XML data trying to find the data I’m looking for.

I just came across a way to make life way easier last night with the simple “tidy” program.

Simply pipe your unformatted XML through this command, and out will come nicely indented and easy to read XML.

tidy -i -xml -utf8

Installing Apache and PHP from source on Leopard

For as long as I can remember, I’ve done web development by working directly on a system running a web server, so that I’m editing files directly in a live document root. For a good part of my career, this has meant that I’ve worked on a Linux system running Apache, PHP, and MySQL.

For the past 6 months, though, I’ve had an Apple MacBook running Mac OS Leopard. Leopard comes pre-installed with Apache and PHP as part of the OS, so for many people the task of installing this web platform is already complete.

If you need any custom options in either Apache or PHP, however, and many people do, you’ll have to download and compile the source yourself. I haven’t found this to be very well documented. So, for the sake of all mankind (but for my own memory, really), I am documenting the process here.

Step 1. Installing Apache

Download the latest source from http://www.apache.org/. I have a directory called ~/src, and I’ll untar the downloaded file in there.

Here are the commands, from the base of the httpd source directory:

$ ./configure --enable-layout=Darwin --enable-so --with-included-apr
$ make
$ sudo make install

Step 2. Installing PHP

PHP has tons of available config options, and I have many of them turned on for my machine. On a production system, best practice would dictate that you identify which options you acutally need, and only compile those in. But in this case, we want to have a bunch of stuff turned on.

To make it easier on myself, I create a file called “config.txt” which contains a configure command with all of the options I use. I copy this into each new version of the PHP source that I compile.

Here’s the contents of that file:

./configure \
–prefix=/usr \
–sysconfdir=/etc \
–with-config-file-path=/etc \
–localstatedir=/var \
–mandir=/usr/share/man \
–infodir=/usr/share/info \
–with-apxs2=/usr/sbin/apxs \
–with-mcrypt=/usr/local \
–with-ldap=/usr \
–with-kerberos=/usr \
–enable-cli \
–enable-soap \
–with-zlib-dir=/usr \
–enable-exif \
–enable-ftp \
–enable-mbstring \
–enable-mbregex \
–enable-sockets \
–with-iodbc=/usr \
–with-curl=/usr \
–with-config-file-path=/etc \
–with-mysql-sock=/tmp/mysql.sock \
–with-mysqli=/usr/local/mysql/bin/mysql_config \
–with-mysql=/usr/local/mysql \
–with-openssl=/usr \
–with-xmlrpc \
–with-xsl=/usr \
–with-libxml-dir=/usr \
–with-iconv=/usr \
–with-pdo-mysql=/usr/local/mysql/bin/mysql_config \
–with-gd \
–with-jpeg-dir=/usr/local \
–with-png-dir=/usr/local \
–with-freetype-dir=/usr/local

Notice there are a few things at the end, jpeg, png, and freetype, as well as mysql. These are things that I’ve installed previously. If you don’t have them on your system, you should pull these config options out, otherwise you’ll probably get errors.

To compile, I do:

$ sh < config.txt
$ make
$ sudo make install

That first command will execute the ./configure command in the text file. Why don’t I do a .sh file and make it a shell script? I just don’t.

Step 3. Get back to work

That’s it! At least when fixing a clobbered install from a security update. If you want to know how to install MySQL or any of the other stuff let me know in the comments and I’ll dive further into this. I hope you find this useful!