Category Archives: mac

Steve Jobs, 1955 – 2011

For me, it wasn’t the iPod, iPhone or iPad but the Mac that was Steve Jobs’ greatest success. After buying an indigo iMac in 2000, it reignited my passion for computing and I never looked back. The Mac made computing pleasurable, and for that I will be eternally grateful to Steve’s vision and passion. A truly inspiring man.

Thanks, Steve.

Steve Jobs on Apple homepage

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Install mcrypt PHP extension on Mac OS X Lion

Important: This article was originally published in 2011, and I wouldn’t recommend you use mcrypt in your PHP project any more (reasons why). If you absolutely need it… then read on….

mcrypt php extension

If you have a need to install the mcrypt extension for PHP, for example if you need to use phpMyAdmin, Magento or Laravel, then these instructions are for you.

Thankfully, it is becoming simpler to install PHP extensions than with previous versions of OS X.

Xcode

The Xcode package installs the necessary tools which are needed during the PHP extension compilation process. Make sure you have at least Xcode v4.1 installed; the install package (“Install Xcode”) is available in your “Applications” folder.

If you are running Xcode 4.3 or above, please check you have the command line tools installed before proceeding.

Autoconf

The most recent version of Xcode does not include autoconf which is a pre-requisite. To check that you have it, run the following command in your Terminal:


autoconf --version

If you see output similar to the following, then it means you have it installed — skip to the libmcrypt section.


autoconf (GNU Autoconf) 2.61
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License .
There is NO WARRANTY, to the extent permitted by law.

Written by David J. MacKenzie and Akim Demaille.

If you get a command not found error, then you will need to perform the following to install autoconf:


cd /tmp
curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar zxvf autoconf-latest.tar.gz
cd autoconf-2.69
./configure; make
sudo make install

libmcrypt

libmcrypt is the library that provides the encryption functions. We need to install this before building the PHP extension.

  • Open up Terminal.app
  • Download libmcrypt from sourceforge
  • Unpack the archive somewhere
  • cd libmcrypt
  • ./configure
  • make
  • sudo make install

PHP Extension

Once we have libmcrypt installed, we can build the PHP extension. One important point: even though PHP 5.3.8 is now the default since Mac OS X 10.7.3, attempting to compile with these sources results in the following error:

php-5.3.8/ext/mcrypt/mcrypt.c:283: error: ‘PHP_FE_END’ undeclared here (not in a function)

Therefore, we need to use PHP 5.3.6 sources which compiles fine and still works with 10.7.3.

You should see output similar to the following:

Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
  • ./configure
  • make
  • sudo make install

On successful install, you will see the following message:

Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20090626/

To enable the module, include the following line in your /etc/php.ini file:

extension = mcrypt.so

Finally, restart your Apache server:

sudo apachectl restart

And that’s it: you should now be able to utilise the functions, as detailed in the PHP mcrypt documentation.

P.S. – Looking for a reliable hosting provider for your PHP projects? I recommend Clook:

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Mac OS X Lion PHP upgrade – php.ini and Suhosin

If you have upgraded from Snow Leopard to the new OS X Lion, you will notice PHP has also been upgraded – from 5.2 to 5.3.

A couple of points that I noticed post-install. Firstly, my existing /etc/php.ini file was moved to /etc/php.ini-5.2-previous. Restoring this was trivial:

sudo cp /etc/php.ini-5.2-previous /etc/php.ini

However, I noticed that extensions previously installed under /usr/lib/php/extensions/no-debug-non-zts-20090626/ had been removed. So, if you have extensions that you wish to still use with 5.3, they will need to be re-built.

I also noticed that Apple have included the Suhosin patch and extension. Suhosin is part of the Hardened-PHP project which aims to protect PHP applications against buffer-overflow and format string vulnerabilities. In theory, this functionality should be transparent to your application – no configuration or code changes are required.

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Install memcached PHP extension on OS X Snow Leopard

Memories

memcached is a very useful memory object caching system, which can be used to increase the performance of your dynamic scripts by caching database calls.

This guide will explain how to install the memcached system, including the PHP extension, on Mac OS X 10.6.

Xcode

The Xcode package installs the necessary versions of tools like autoconf which is needed during the PHP extension compilation process. Make sure you have Xcode 3.2 installed; the install package is available on the Snow Leopard install DVD under the “Optional Installs” folder.

libevent

libevent is a pre-requisite for memcached.

  • cd /tmp; curl -O http://www.monkey.org/~provos/libevent-1.4.12-stable.tar.gz
  • tar zxvf libevent-1.4.12-stable.tar.gz
  • cd libevent-1.4.12-stable
  • ./configure; make
  • sudo make install

memcached

memcached is the daemon responsible for actually storing and retrieving arbitrary objects for your applications.

  • cd /tmp; curl -O http://memcached.googlecode.com/files/memcached-1.4.1.tar.gz
  • tar zxvf memcached-1.4.1.tar.gz
  • cd memcached-1.4.1
  • ./configure; make
  • sudo make install

libmemcached

libmemcached is the shared library that will allow clients, in this case PHP, access the memcached daemon.

  • Download libmemcached, move to /tmp and unpack
  • cd libmemcached-0.31
  • ./configure; make
  • sudo make install

php extension

Now we are ready to prepare the PHP extension to memcached, which is available from pecl.

  • cd /tmp; pecl download memcached
  • gzip -d < memcached-1.0.0.tgz | tar -xvf -
  • cd memcached-1.0.0; phpize

You should see output similar to the following:

Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626

  • ./configure; make
  • sudo make install

On a successful install, you will get the following message:

Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20090626/

Modify your php.ini configuration file and make sure you have the following line included:

extension = memcached.so

You can then restart your Apache server:

  • sudo apachectl restart

to make the memcached functionality available in your scripts.

memcached php extension

References

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Fix PHP timezone warnings in OS X Snow Leopard

The standard Mac install of PHP has always been somewhat quirky, and 10.6 is no exception. One of the most obvious issues occurs when attempting to use date/time functions. PHP 5.3 requires that the date.timezone setting is available. Without this, you will receive a warning similar to the following:

Warning: getdate() [function.getdate]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /Users/gscott/Sites/hello-world.php on line 9

The solution is to edit (or create, if it doesn’t exist) /private/etc/php.ini and make sure a setting exists for date.timezone. For example:

date.timezone = Europe/London

After making the change, restart Apache

sudo apachectl restart

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

mcrypt support for PHP on 64 bit Mac OS X 10.5

Please note: The article below refers to installing mcrypt on Mac OS X 10.5. If you have 10.6 Snow Leopard, please see my updated guide: Install mcrypt PHP extension on OS X Snow Leopard

Adding additional functionality to the standard Apple-supplied PHP on Mac OS X 10.5 is a little tricky if you are running a 64 bit processor such as the Intel Core 2 Duo. The reason is that any dynamic extensions that you add will need to be 64 bit, and many shared libraries by default will compile as 32 bit binaries. Trying to use a 32 bit extension with a 64 bit PHP results in the following unfriendly error message:

PHP Warning: PHP Startup: Unable to load dynamic library './mcrypt.so' - (null) in Unknown on line 0

mcrypt is a good example of a useful extension that can be added to PHP with a little bit of effort:

  • Open up your Terminal.app
  • To explicitly build for 64 bit architecture export CFLAGS="-arch x86_64"
  • Download libmcrypt from sourceforge http://sourceforge.net/projects/mcrypt
  • Unpack the archive
  • cd libmcrypt
  • ./configure --disable-shared
  • make
  • sudo make install
  • download PHP 5.2.6 source from http://www.php.net/get/php-5.2.6.tar.bz2/from/a/mirror
  • unpack the archive and go into the php-5.2.6/ext/mcrypt/ dir
  • phpize
  • ./configure
  • make
  • sudo make install
  • verify the extension is 64 bit: file /usr/lib/php/extensions/no-debug-non-zts-20060613/mcrypt.so

/usr/lib/php/extensions/no-debug-non-zts-20060613/mcrypt.so: Mach-O 64-bit bundle x86_64

To actually use the extension, you can simply create a symbolic link to it. For example:

  • cd ~/Sites
  • ln -s /usr/lib/php/extensions/no-debug-non-zts-20060613/mcrypt.so

Example code: mcrypt.php

Drop the following code into your ~/Sites directory to verify everything is working:

    <?php
    
    if ( ! extension_loaded('mcrypt') ) {
        dl('mcrypt.so');
    }
    
    $key   = "this is a secret key";
    $input = "Let us meet at 9 o'clock at the secret place.";
    
    $td = mcrypt_module_open('tripledes', '', 'ecb', '');
    $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    mcrypt_generic_init($td, $key, $iv);
    $encrypted_data = mcrypt_generic($td, $input);
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);
    
    print_r($encrypted_data);
    
    ?>

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Shared memory fix for PostgreSQL Mac installation

EnterpriseDB have kindly created a one-click installer for PostgreSQL, but unfortunately it doesn’t work out-of-the-box, at least not on my MacBook Pro. The problem is down to the amount of shared memory that is configured in OS X; by default it is 4Mb, and PostgreSQL requires 32Mb:

Postgres installer error

The error message suggests looking at the README file, which actually doesn’t exist. Luckily, there’s a simple fix; to increase the shared memory to the required 32Mb, create or edit the /etc/sysctl.conf file and include the following lines:

kern.sysv.shmall=8192
kern.sysv.shmseg=64
kern.sysv.shmmni=256
kern.sysv.shmmin=1
kern.sysv.shmmax=33554432

Reboot your machine for the settings to take effect, and re-launch the PostgreSQL installer which should now work as normal.

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Installing Subversion 1.5 on Mac OS X

My current project at Yahoo! is using a Subversion repository for version control, as opposed to the usual CVS (thankfully). Unfortunately, it turns out that the svn client installed on Mac OS X Leopard up to and including 10.5.6, is 1.4 whereas the “best” release is 1.5.

It’s very simple to get the newer 1.5 version up and running by compiling from source:

This will install Subversion 1.5 in your /usr/local path.

I added the --without-sasl option to prevent the following error from occurring when committing files:

svn: Commit failed (details follow):
svn: Cannot negotiate authentication mechanism

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

GoboLinux proves that AmigaOS was ahead of its time

GoboLinux is described as “an alternative Linux distribution which redefines the entire filesystem hierarchy”. Not particularly snappy, but the concept behind it is very clean and simple: there is no need for package management, because every program resides in its own directory. This is a great concept because it means you don’t get libraries scattered around your system which can cause dependency problems, and makes un-installing applications much easier.

GoboLinux uses the filesystem to organise program installation so that, for example, OpenOffice and all of its required files would be installed under /Programs/OpenOffice/3.0/.

Mac OS X also uses this concept: right-click on an application in /Applications and select the Show Package Contents option to see this in action.

A post entitled An old OS idea is new again: non-installation by Carl Sassenrath reminded me that the AmigaOS was doing this back in 1985.

I have a lot of time for the Amiga, and particularly its OS. As well as this “non-installing” feature, one of my favourite concepts was the DataType. This was a method of allowing the OS and its applications to recognise new filetypes by abstracting the loading, decoding and saving of file formats into a file descriptor. It meant, for instance, that you could add PNG support to a graphics application simply by dropping a PNG DataType file into the Prefs/Datatypes directory.

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Synchronize iCal with Yahoo! Calendar

Update 26th October 2011: Are you receiving a “502” error from iCal? Please see my more recent post iCal 502 error when syncing with Yahoo! Calendar for more details.

The new beta of Yahoo! Calendar now supports the CalDAV protocol, meaning that sharing and synchronizing with desktop calendaring applications is possible.

iCal has supported CalDAV since version 3.0 shipped with Mac OS X 10.5 Leopard, so it is possible to get it working with Yahoo! Calendar. After completing the following steps, any events that you create in the web-based Calendar will be replicated to iCal, and vice-versa.

What you will need:

  • A Yahoo! account. In the example, we use the username yahoouser
  • Access to the new Calendar Beta.
  • iCal version 3 or above

Step 1:

  • In iCal, select the Preferences… from the iCal menu.
  • Click on the Accounts icon

  • Click on the plus button to create a new CalDAV account
  • Enter a description, such as Yahoo! Calendar, your Yahoo! username and password.
  • Click the Server Options link and enter the following into the Account URL field:
https://caldav.calendar.yahoo.com

  • Click the Add button.


Your Yahoo! Calendar should now be synchronized with iCal, refreshing every 15 minutes: you should see it listed on the left hand side of your iCal window underneath the calendars stored on your Mac.

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn