Tutorials

Mac OS X Lion Upgrade PHP Extensions Tutorial: ImageMagick and More.

After upgrading my Mac OS X Snow Leopard to Mac OS X Lion, I noticed that some of my PHP extensions that I had compiled to work with the Apple PHP 5.3.6 binary had been removed. Some, not all. Which I assume is due to them having been compiled 4-way binary compatible (PowerPC and i386/x86_64). Since Lion no longer supports PowerPC, it seems that all the extension files that had PowerPC in them were removed. Xdebug was still there, but all the rest were gone. Below is the process I performed to get everything back.

Step 1:
Download and install MacPorts 2.0.0 for Mac OS X Lion.

Step 2:
In Terminal, run the following commands. The first one may take a while to update the binaries as it compiles them.

sudo port upgrade outdated
sudo port uninstall inactive

Step 3:
Download and install MySQL 5 (currently at mysql-5.5.15-osx10.6-x86_64 as of this writing) for Mac OS X.

You may not need to install MySQL, though I chose to do so as I wanted to update to the 64bit System Preferences panel, since I was running an earlier version of MySQL 5 previously.

Step 4:
I also noticed that my /etc/php.ini file was moved to /etc.php.applesaved and no longer called any of my PHP extensions I had set.

In Terminal, run the following:

sudo cp /etc/php.ini.applesaved /etc/php.ini
sudo apachectl graceful

Step 5:
Continue on to my PHP extensions tutorial for Snow Leopard and begin with Step 5 if you don’t have ImageMagick installed, Step 6 if you do.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Snow Leopard PHP and IMAP Support

Seeing as how the stock Apple Mac OS X 10.6 Snow Leopard PHP 5.3 doesn’t come with IMAP extension support, I realized it was time to add it in to build a tool to extract data from my gmail account emails. Here is the steps I took to get it installed and working.

Step 1:

Download IMAP source code. (2007e as of writing this). Without this, trying to compile the IMAP PHP extension will give you errors and will refuse to compile.

Unpack the imap-2007e.tar.gz file.

In Terminal:

sudo mv ~/Downloads/imap-2007e /usr/local/imap-2007
cd /usr/local/imap-2007
make osx
sudo cp c-client/c-client.a c-client/libc-client.a

Step 2:

Download PHP 5.3.0 source code for the php imap extension here. I already had a copy from my previous extension tutorial, so I just used that copy.

Unpack the file php-5.3.0.tar.gz. We will only need to use the code within the ext/imap directory. No need to compile all of PHP for this.

In Terminal:

cd ~/Downloads/php-5.3.0/ext/imap
phpize
./configure --with-imap==/usr/local/imap-2007 --with-kerberos --with-imap-ssl
make
sudo cp modules/imap.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

Step 3:

Add in the extension location to the php.ini file.

In Terminal:

sudo pico /etc/php.ini

I placed the following after all the commented out lines for extensions:

extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/imap.so

After you have placed that line in there, press Control-X to exit and save.

Step 4:

Restart Apache.

In Terminal:

sudo apachectl graceful

Now you should be able to see the imap extension installed in your stock Apple PHP.

VN:F [1.9.22_1171]
Rating: 7.6/10 (5 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 2 votes)

Snow Leopard PHP Extensions Installation Tutorial

This will help you to setup imagick, magicwand, xdebug, mcrypt and memcached for Snow Leopard’s bundled PHP 5.3.0. Please do expect the installation of ImageMagick to take a bit of time, as it requires a large number of packages. I’m doing it all my preferred way. If you have another way that is faster or better, I’d be glad to take your suggestions and make this tutorial more streamlined.

Step 1:

Make sure you have XCode 3.2 for Snow Leopard installed, from the Snow Leopard install DVD.

Step 2:

Download MacPorts for Mac OS X 10.6 Snow Leopard here.

If you have previously installed MacPorts and installed software with it in Mac OS X 10.5, run this first to remove it, as it won’t work in Snow Leopard anymore.

In Terminal:

sudo rm -rf /opt/local \
/Applications/MacPorts \
/Applications/DarwinPorts \
/Library/Tcl/macports1.0 \
/Library/Tcl/darwinports1.0 \
/Library/LaunchDaemons/org.macports.* \
/Library/StartupItems/DarwinPortsStartup \
/Library/Receipts/MacPorts*.pkg \
/Library/Receipts/DarwinPorts*.pkg \
~/.macports

Step 3:

Open the MacPorts-1.8.0-10.6-SnowLeopard.dmg file, and install the MacPorts package file.

Step 4:

To hide the /opt folder from Finder view that is visible after installing MacPorts.

In Terminal:

sudo chflags hidden /opt

Step 5:

By default, MacPorts for Snow Leopard should use x86_64 arch instead of ppc/i386, so you shouldn’t have to worry much here.

This part most likely will take the longest of all things in the tutorial, as it requires a large group of individual packages. You can cook dinner, eat it, and you might still be waiting for this to complete after you’ve finished eating. It took about a half hour for it to complete on my MacBook.

In Terminal:

sudo port install imagemagick

Step 6:

Download imagick here.

Unpack the file imagick-2.3.0.tgz.

In Terminal:

cd ~/Downloads/imagick-2.3.0/imagick-2.3.0
phpize
./configure --with-imagick=/opt/local
make
cd modules
sudo cp imagick.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

Step 7:

Download magickwand here.

Unpack the file MagickWandForPHP-1.0.8.tar.gz.

In Terminal:

cd ~/Downloads/MagickWandForPHP-1.0.8/
phpize
./configure --with-magickwand=/opt/local
make
cd modules
sudo cp magickwand.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

Step 8:

Download xdebug here.

Unpack the file xdebug-2.0.5.tgz.

In Terminal:

cd ~/Downloads/xdebug-2.0.5/xdebug-2.0.5
phpize
./configure
make
cd modules
sudo cp xdebug.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

Step 9:

In Terminal:

sudo port install libmemcached

When it completes, type this into Terminal:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.memcached.plist

Step 10:

Download memcached here.

Unpack the file memcached-1.0.0.tgz.

In Terminal:

cd ~/Downloads/memcached-1.0.0/memcached-1.0.0/
phpize
./configure --with-libmemcached-dir=/opt/local
make
cd modules
sudo cp memcached.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

Step 11:

Download libmcrypt here.

Unpack the file libmcrypt-2.5.8.tar.bz2.

In Terminal:

cd ~/Downloads/libmcrypt-2.5.8/
./configure --disable-posix-threads --enable-static
make
sudo make install

Step 12:

Download PHP 5.3.0 source code for the mcrypt extension here.

Unpack the file php-5.3.0.tar.gz. We will only need to use the code within the ext/mcrypt directory. No need to compile all of PHP for this.

In Terminal:

cd ~/Downloads/php-5.3.0/ext/mcrypt
phpize
./configure
make
cd modules
sudo cp mcrypt.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

Step 13:

In Terminal:

cd /etc
sudo cp php.ini.default php.ini
sudo pico php.ini

Search for:

display_errors

Set this to:

display_errors = On

Search for:

html_errors

Set this to:

html_errors = On

I placed the following after all the commented out lines for extensions:

;;;;;;
extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so
extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/magickwand.so
extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/imagick.so
extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/memcached.so
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
xdebug.default_enable = On
xdebug.collect_params = 4
xdebug.trace_format = 1
xdebug.show_local_vars = On
xdebug.dump_globals = On
xdebug.show_exception_trace = On
xdebug.collect_assignments = 1
;;;;;;

Set your default timezone. I’ll show mine as an example.

date.timezone = America/New_York

Set your mysql default port.

mysql.default_port = 3306

Press Control-X to exit, it will ask if you want to save changes, so press Y for Yes, and press Enter save and exit completely.

Step 14:

Restart Apache.

In Terminal:

sudo apachectl graceful

That should do it, as this is the exact steps I took to install all of these just now. And everything worked for me just as typed.

Hope this helps you out.

Enjoy.

VN:F [1.9.22_1171]
Rating: 9.7/10 (24 votes cast)
VN:F [1.9.22_1171]
Rating: +12 (from 16 votes)