1 January 2010
I was disappointed with the fact that I was no longer able to export ensembles when I upgraded to some new Apple hardware. Since it was running Mac OS X 10.6 Snow Leopard, I needed to make some changes to my local development environment to get my several Symphony installs up and running again.
Snow Leopard ships with PHP 5.3, which means that the XSL extension is included by default. Great! However, the Zip extension is not included. Not so great, if you want to be able to create Symphony Ensembles. I’ve always done my development with the default Mac OS X installs of Apache, and I have a similar set up on my iMac G3, Mac G5, the Intel iMac at work and now my new MacBook Pro. Not wanting to now switch to MAMP, I was determined to find a way to get the ZIP extension installed for the default PHP install in Snow Leopard.
Here are the resources that helped me in my quest:
Adding the Zip Extension to PHP for Mac OS X 10.6 Snow Leopard
You will need to be familiar with command line tools in Mac OS X. I tend to prefer using Terminal in Coda. The following process also requires the latest Xcode Tools from Apple in order to compile the Zip extension from the PHP source code. If you’d rather skip the compile process, try downloading one of the
zip.so files mentioned at the end of this post.
Install Xcode Tools
First, install Xcode 3.2 from the OS X DVD, or visit the Apple Developer Center to download the latest Xcode Tools:
Double-click on the Xcode.mpkg installer to install the Essentials, System Tools and UNIX Dev Support components of the Xcode tools. You may only need the UNIX Dev Support tools, but the bulk of the install is the 1.76 GB Essentials component, so it doesn’t hurt to include the rest of the components, except that I’ve skipped the Mac OS X 10.4 Support.
Download PHP Source
Next, download the PHP source code, which also contains the source for the extensions. We don’t need to recompile PHP, since all we’re going to do is add the extension file to the existing PHP install, configure the php.ini file and restart the server to enable the Zip extension.
Unpack the PHP source code. I’ve placed the unpacked directory in my home directory:
Prepare the Build Settings
Instruct our system to build universal binaries, that will work on both 32 and 64 bit systems by entering the following commands in a terminal console:
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bind_at_load" export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET
Compile the Zip Extension
One of the prerequisites for compiling the extension will be to have the
pcre.h file available during the compile process, according to the instructions supplied by the one of the comments to copy this file:
sudo cp ~/php-5.3.1/ext/pcre/pcrelib/pcre.h /usr/include/php/ext/pcre/
Then, navigate to the Zip extension directory:
And run the following commands to compile the
phpize ./configure make
The extension file will be created here:
To add the extension to the default PHP install, copy the compiled
zip.so file to the extensions library directory.
sudo cp ~/php-5.3.1/ext/zip/.libs/zip.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
Ensure that the file is executable:
cd /usr/lib/php/extensions/no-debug-non-zts-20090626/ chmod +x zip.so
Then, configure PHP to include the extension by creating a
php.ini file (if it has not already been created).
sudo cp /etc/php.ini.default /etc/php.ini
There are a couple settings that must be configured in the
php.ini file to include the Zip extension. Tell PHP where to find the extensions library:
extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20090626/"
And tell PHP to include the Zip extension
I have included both these lines at the end of the
To check whether the extension has been successfully linked by the
php.ini file, run the following command to list the available PHP extensions:
Here’s where you can see the results of trying to include an extension file that has been compiled for the wrong system architecture:
/usr/lib/php/extensions/no-debug-non-zts-20090626/zip.so: mach-o, but wrong architecture in Unknown on line 0
Configure the MySQL Socket for PHP
I found that the new
php.ini file had defaults that differed from my local hosting environment. Having installed MySQL 5.1 using the package installer available from dev.mysql.com, I found that the new configuration file broke all connections to my databases. To fix this, I modified the following lines of the
php.ini file to point to the correct location for the MySQL socket file. The default settings looked like this:
mysql.default_port = mysql.default_socket = /var/mysql/mysql.sock
However, both of these lines needed to be changed to reflect that actual location of the socket file:
mysql.default_port = /tmp/mysql.sock mysql.default_socket = /tmp/mysql.sock
With the PHP settings properly configured, all that is necessary to enable the Zip extension is to restart the Apache server:
sudo apachectl graceful
Now, I find that everything is again working as it should, and I am able to export Symphony Ensembles again. Now I have my development environment back again, and I hope I can begin to continue to develop some of my experimental ensembles into useful applications.
For anyone who has the same architecture, I have attached the
zip.so file, so you can skip the whole Xcode Tools download and extension compilation process. For those who have a different architecture, try the
zip.so file provided by Greg Hughes.
Filed Under: Web