Install YAML Pecl PHP Extension on MAMP

Mindblip picture Mindblip · Jul 16, 2011 · Viewed 7.6k times · Source

I'm working on a project with a number of developers over Git and the existing codebase uses PECL YAML PHP extension (v1.0.1).

I have tried a number of steps to install the PECL YAML extension on my MAMP server and to no joy!

I am assuming the other developers are on Linux.

First couple of attempts at install revealed this error in my php_error_log:

"[16-Jul-2011 11:29:13] PHP Warning: PHP Startup: Unable to load dynamic library '/Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/yaml.so' - dlopen(/Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/yaml.so, 9): no suitable image found. Did find: /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/yaml.so: mach-o, but wrong architecture in Unknown on line 0"

After a large amount of time googling I realised that I wasn't alone and it's because my extension that I compiled using "./pecl i yaml" was a 64 bit version

"file yaml.so": yaml.so: Mach-O 64-bit bundle x86_64

However, comparing this to working extensions on my MAMP setup i.e. "file xdebug.so":

xdebug.so: Mach-O universal binary with 2 architectures
xdebug.so (for architecture ppc): Mach-O bundle ppc
xdebug.so (for architecture i386): Mach-O bundle i386

So I discovered a number of blogs that helped me to identify the exact problem.

Can't run 64 bit extensions on 32 bit MAMP server - makes sense.

My install process is:

  • download PECL YAML source
  • extract tar and cd into module source
  • phpize inside module directory
  • run .configure using a command from blogs:

    "CFLAGS='-O3 -fno-common -arch i386 -arch x86_64 -g -Os' LDFLAGS='-O3 -arch i386 -arch x86_64′ CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64 -g -Os' ./configure –-disable-dependancy-tracking –-disable-shared -enable-static"

  • make

  • copy created module from modules/yaml.so to MAMP:

    "sudo cp modules/yaml.so /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/."

The above solution seems to have worked for everyone but me.

My error log now reports this:

[16-Jul-2011 11:09:25] PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'yaml.so' in Unknown on line 0

I've spent a good couple of hours on this now and need your help.

All I'm actually trying to do is parse YAML in PHP.

I have 2 options:

  1. Fix it and breath a sign of relief

  2. Use a PHP YAML parsing class instead and avoid this extension in the future

The issue with option 2 is that the codebase will change due to my inability to install an extension.

Any advice or a solution would be greatly appreciated.

Cheers

Answer

Rifat picture Rifat · Nov 30, 2011

If you have Homebrew installed then you can do:

brew install libyaml --universal

Otherwise install the latest libyaml.

You can build for both 32 & 64 bit Intel by setting CFFLAGS and LDFLAGS to -arch i386 -arch x86_64.

Then, install PEAR/PECL (you can also follow the instructions here)

wget http://pear.php.net/go-pear.phar
sudo php -d detect_unicode=0 go-pear.phar

By default it'll install in ~/pear/ directory. Now run

sudo ~/pear/bin/pecl install yaml

Then, take care of the so file.


This nice article will demonstrate how you can install MAMP stack manually.