How to install PHP APC in OS X

I assume you already have PEAR/PECL available. I am using the Mac OS X PHP environment that is provided by Apple’s XCode but it shouldn’t matter how you get your PHP. First you need to update your channels:

[code lang=”bash”]kahwee:~ kahwee$ sudo pear update-channels
Updating channel “”
Channel “” is up to date
Updating channel “”
Channel “” is up to date
Updating channel “”
Channel “” is up to date[/code]

Continue reading “How to install PHP APC in OS X”

How to compile PHP mcrypt extension in OS X

I have just switched from using MacPorts to using Homebrew and I decide to use what’s provided by Apple Mac OS X as much as possible. This means that I’ll be using the Apache and PHP 5.3.3 that is provided as part of Apple’s XCode. Unfortunately, there are some extensions that are just not available as part of Apple’s PHP package. One of them would be mcrypt.

One of the ways to get mcrypt in would be to recompile the entire PHP source code. That method works but I would prefer using Apple’s stock PHP and just load a few additional modules. The following instructions documents how I managed to install PHP mcrypt by compiling the extension. I hope it can help in your work too.

Firstly I got libmcrypt from Homebrew. To do that:

[code lang=”bash”]brew install libmcrypt[/code]

libmcrypt is needed for PHP mcrypt. You’ll also need to download a copy of PHP source code. The PHP that comes with my OS X is 5.3.3:

[code lang=”bash”]kahwee:~ kahwee$ which php
kahwee:~ kahwee$ php -v
PHP 5.3.3 (cli) (built: Aug 22 2010 19:41:55)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
kahwee:~ kahwee$ [/code]

So I downloaded and extracted my copy to: /Users/kahwee/Packages/php-5.3.3

All the PHP extensions are located here: /Users/kahwee/Packages/php-5.3.3/ext. I am going to require mcrypt so let’s get the extension (.so) file.

Current I’m in /Users/kahwee/Packages/php-5.3.3/ext/mcrypt/module/mcrypt. Let’s start by running phpize, it’s a utility to prepare for the build environment.

[code lang=”bash”]kahwee:mcrypt kahwee$ phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626[/code]

Run aclocal, then ./configure:

[code lang=”bash”]kahwee:mcrypt kahwee$ aclocal
kahwee:mcrypt kahwee$ ./configure
checking for grep that handles long lines and -e… /usr/bin/grep
checking for egrep… /usr/bin/grep -E
checking for a sed that does not truncate output… /usr/bin/sed

Finally we can make the extension:

[code lang=”bash”]kahwee:mcrypt kahwee$ make
/bin/sh /Users/kahwee/Packages/php-5.3.3/ext/mcrypt/libtool –mode=compile cc -I. -I/Users/kahwee/Packages/php-5.3.3/ext/mcrypt -DPHP_ATOM_INC -I/Users/kahwee/Packages/php-5.3.3/ext/mcrypt/include -I/Users/kahwee/Packages/php-5.3.3/ext/mcrypt/main -I/Users/kahwee/Packages/php-5.3.3/ext/mcrypt -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /Users/kahwee/Packages/php-5.3.3/ext/mcrypt/mcrypt.c -o mcrypt.lo
mkdir .libs


Libraries have been installed in:

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the -LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the
DYLD_LIBRARY_PATH’ environment variable
during execution

See any operating system documentation about shared libraries for

more information, such as the ld(1) and manual pages.

Build complete.
Don’t forget to run ‘make test’.


Now you can find your extension in the module folder. For my case, it is found in /Users/kahwee/Packages/php-5.3.3/ext/mcrypt/modules/