The watch Linux command line tool

24th July 2009

I'm sure everyone else already knows about watch, but it's new to me. This little utility executes a program repeatedly at a set interval and displays its output.

I've been using it with mysqladmin's processlist command like this:


watch -n 1 /usr/bin/mysqladmin -uroot -pMYPASSWORD  processlist

Note that this does put your password on display at the top of the command window whilst watch is running. If you don't want that, you could write a little bash script instead like this one from a friend of mine:


#!/bin/sh

while :
do
sleep 1
clear
mysqladmin -uroot -pMYPASSWORD processlist 
done

Either way, we get a display of the MySQL process list every second in a Terminal window and it becomes very easy to see which processes are causing trouble.

Setting up PHP on OS X Leopard

5th March 2009

In the vein of some of Lorna's articles, this is more a note for myself than anything else. Not everything is explained in detail as it assumes you know how to use a command line...

These are the steps I take to get the Apple supplied PHP working with GD, PDO_MySQL and Xdebug working on OS X 10.5.

/usr/local

Ensure that the following directories exist:

    sudo mkdir /usr/local/include
    sudo mkdir /usr/local/bin
    sudo mkdir /usr/local/lib
    sudo mkdir -p /usr/local/man/man1

Run Apache in 32 bit mode

This saves us having to compile our own MySQL as MySQL doesn't offer a "fat" binary

  1. cd /System/Library/LaunchDaemons
  2. sudo vim org.apache.httpd.plist
  3. Immediately after the line containing <array> add:
        <string>arch</string>
        <string>-i386</string>
    
  4. Reboot

MySQL

  1. Download the 32bit version of MySQL 5.0.x for OS X 10.5 from mysql.com and install the pkg, the startup item and the pref pane.
  2. Add /usr/local/mysql/bin to the path: vim ~/.bash_profile and add:
        export PATH=~/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH
        export EDITOR=vim
    

    at top of file. (Note that we set EDITOR whilst we are here so that svn is happy!)

  3. Set up MySQL root password:
        mysqladmin -u root password {new-password}
        mysqladmin -u root -p{new-password} -h localhost password {new-password}
        mysqladmin -u root -p reload
    

    Quit Terminal to flush the history to file. Restart Terminal and remove the history file: rm .bash_history so that {new-password} isn't in plain text on the disk.

  4. Set the correct socket information for PHP. Ensure MySQL is running via the System Preferences panel then:
        sudo mkdir /var/mysql
        sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
    

Rest of Apache setup

  1. cd /etc/apache2
  2. sudo vim httpd.conf
  3. Find #LoadModule php5_module libexec/apache2/libphp5.so and remove the leading #
  4. Find AllowOverride None within the <Directory "/Library/WebServer/Documents">section and change toAllowOverride All so that .htaccess files will work.
  5. Restart Apache: sudo apachectl restart
  6. Open Finder and navigate to /Library/WebServer/Documents/
  7. Create a new folder called "orig" and place all files currently in the Documents folder into it.
  8. Create a new file called info.php with <?php phpinfo(); inside it.
  9. Use Safari to navigate to http://localhost/info.php and check that the PHP version is displayed (5.2.6 at the time of writing).

php.ini

  1. cd /etc
  2. sudo cp php.ini.default php.ini
  3. sudo chmod ug+w php.ini
  4. sudo chgrp admin php.ini
  5. vim php.ini (assuming your user is a member of the admin group) and change settings appropriately. Change:
        error_reporting  =  E_ALL | E_STRICT
        extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20060613"
    

    You must set the extension dir correctly. (Commenting the line out also works...)

PHP extensions

The supplied PHP doesn't come with pdo_mysql, pear or gd, so fix it.

  1. Download the correct version of PHP from http://www.php.net/releases/. (5.2.6 at time of writing)
  2. Create a directory called src in your home directory and unpack the PHP source. This creates /Users/rob/src/php-5.2.6/ in my case.

pdo_mysql

  1. cd ~/src/php-5.2.6/ext/pdo_mysql.
  2. phpize
  3. MACOSX_DEPLOYMENT_TARGET=10.5 \
    CFLAGS='-O3 -fno-common -arch i386' \
    LDFLAGS='-O3 -arch i386' \
    CXXFLAGS='-O3 -fno-common -arch i386' \
    ./configure --prefix=/usr --with-pdo-mysql=/usr/local/mysql
  4. make
  5. sudo make install
  6. Edit /etc/php.ini and find the extension_dir line and add after it:
        extension=mysql.so
  7. Restart apache: sudo apachectl restart and check in the phpinfo that pdo_mysql is now loaded.

GD

Installing GD onto the stock PHP install that is supplied with OS X is slightly more complicated than you'd expect because you need to install libjpeg first.

Libjpeg

Libjpeg is available from the Independent JPEG Group.

  1. Download the source code: http://www.ijg.org/files/jpegsrc.v6b.tar.gz
  2. extract to ~/src
  3. cd ~/src/jpeg-6b
  4. cp /usr/share/libtool/config.* .
  5. ./configure --enable-shared
  6. sudo make install
  7. Libjpeg is now installed in /usr/local/lib

GD extension

  1. cd ~/src/php-5.2.6/ext/gd
  2. phpize
  3. MACOSX_DEPLOYMENT_TARGET=10.5 \
    CFLAGS='-O3 -fno-common -arch i386' \
    LDFLAGS='-O3 -arch i386' \
    CXXFLAGS='-O3 -fno-common -arch i386' \
    ./configure --with-zlib-dir=/usr --with-jpeg-dir=/usr/local/lib --with-png-dir=/usr/X11R6 --with-freetype-dir=/usr/X11R6 --with-xpm-dir=/usr/X11R6
  4. make
  5. sudo make install
  6. Edit /etc/php.ini and find the extension_dir line and add after it:
        extension=gd.so
  7. Restart apache: sudo apachectl restart and check in the phpinfo that GD is now loaded.

PEAR

  1. cd ~/src/.
  2. curl http://pear.php.net/go-pear > go-pear.php
  3. Accept defaults, except for installation prefix (1) should be /usr/local
  4. Check that the include_path in /etc/php.ini is correct and includes the PEAR directory (/usr/local/PEAR).

Xdebug

Can't have a PHP development environment without xdebug!

  1. sudo pecl install xdebug
  2. Edit /etc/php.ini and add
        zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"

    after the other extension lines.

  3. Restart apache: sudo apachectl restart and check in the phpinfo that xdebug is now loaded.

PHPUnit

  1. sudo pear channel-discover pear.phpunit.de
  2. sudo pear install phpunit/PHPUnit

It all works on this machines, anyway :)

Updatesee Marc Liyanage's PHP5 packages

TaskPaper

18th November 2007

One of the apps that I've found that I'm using daily is TaskPaper from Hog Bay Software. It's a brilliantly simple idea where all it does is format up a standard text file to make it easier to use as a todo list.

You just start each item with a dash and it will automatically provide a checkbox next to the item. When you tick the checkbox, then a tag, @done, is added to the end of the line and it is crossed out. To aid organisation, any title that ends in a colon is automatically made bold and considered a project. Tags start with a @ symbol and can be used for filtering. For instance, you can get it to display all tasks with the tag of @town to provide a list of items to be done when you next go into town.

All in all, TaskPaper is very simple and very easy to use. You start it up and you can get going straight away.

Obviously, there are a few niggles! Three that I've noticed are:

  • Dragging and dropping of tasks to reorder isn't as smooth as it could be as TaskPaper tends to put the task you are moving into the same line as the task you are trying to insert above.
  • If I've completed all sub-tasks, it would be nice if it automatically marked the parent task as done too. In reverse, it would be handy if it would auto-mark-done all child tasks when I mark their parent task as done.
  • The context menu contains items that don't make sense, such as font and colours.

Niggles, really is the word, isn't it?! I need to stress the application more so that I can find an important thing to complain about!

Hog Bay Software is run by Jesse, who is a really nice guy as he even answered my emailed bug report even though I was just a trial user. I've since bought the product as to my mind it's well worth the money.

I'm now looking for a "diary" type program that will present me with a blank page every day automatically. Bonus points if it allows tagging of pages to help me find stuff I've stored and I'd also like it to store its files in RTF files or similar so that I can take them to Pages with no hassle. So far, I've looked at Journler, Jotter and MacJournal so far, but all require me to start a new entry manually.

Subversion's svn:externals

20th January 2007

I know everyone else is already doing it, but I've only just got around to working out how svn externals works and why it's quite cool.

I've got a Zend Framework application that I'm working on in subversion and it has a lib directory which contains a zf directory. The zf directory is a checkout of the latest trunk version of the framework. Up to to now, I've been doing this manually.

Today I sat down for all of 10 mins and sorted out subversion's svn:externals functionality to make it do the legwork. It's dead easy.

Command line:

cd lib
svn propedit svn:externals .

(Don't forget to ensure that the EDITOR environment variable is set!)

I then added

zf http://framework.zend.com/svn/framework/trunk

in the editor (a file called svn-prop.tmp, apparently) and saved and closed the editor.

All that's required now is an svn update to automatically pull in the Zend Framework code automatically for me.

By the way, you have to do a svn commit to actually commit the propedit change too.

Firefox 2 beta 2

1st September 2006

Beware this beta! A new theme is in the works and it wasn't ready when beta 2 was released...

I use Windows Classic and the tabs are terrible and don't follow my system colours at all.

Very very odd. I'm assuming it'll be fixed by the release of Firefox2 as the regression list is long and being tackled. Jed Brown covers the actual problems in more detail.

Other than the theme, Firefox2 is shaping up quite nicely :)