11

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

Ondrej Slinták
  • 31,386
  • 20
  • 94
  • 126
Mindblip
  • 265
  • 9
  • 16
  • edited question to make it a bit more readable. – Spudley Jul 16 '11 at 14:14
  • Any luck with this? I'm running into the same issue trying to install yaml.so in a MAMP environment. – Adam V. Oct 28 '11 at 17:46
  • 1
    I know this might not be the answer you want to hear but, I would suggest using the MacPorts version of PHP and Apache. – danielrsmith Nov 10 '11 at 14:15
  • I've always had trouble with installing extensions on Mamp and Xampp (mac version). I ended up running a linux vm to get around this issue (Turnkey Linux - Lamp Stack worked great) – ford Dec 01 '11 at 21:47

4 Answers4

17

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.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Rifat
  • 7,628
  • 4
  • 32
  • 46
  • Thanks for your reply, but the steps you outlined are essentially those @Mindblip and almost everyone else facing problems with compiling the yaml extension for MAMP has tried -- without success. The crux is, that the PHP setup that comes with MAMP doesn't recognize the compiled so as valid module. I already tried every possible compiler flags, but the built so is always invalid (as reported by php). :( – petabyte Dec 01 '11 at 17:01
  • @kishkash, Actually I did it without following any guide. I don't use MAMP so, sorry for the wrong solution. – Rifat Dec 01 '11 at 20:35
3

Well, it's not a real solution to your problem. But if you only want to parse YAML I would suggest to use the Symfony YAML class, it's a great easy to use class for parsing YAML. Speed is okay and error messages are quite clear.

Yes, it will change the codebase, but that isn't a bad thing. I think it's a plus when you can avoid using a PECL extension like this, because of the issues you now experience and if you ever need to switch to another servers you will be glad you don't have to check/install 25 PECL extensions (and their correct versions).

So my suggestion, switch to a YAML class. It will make life easier! :)

igorw
  • 27,759
  • 5
  • 78
  • 90
Mac_Cain13
  • 3,611
  • 2
  • 24
  • 38
  • 1
    Why was this downvoted? +1 for viable (and sensible) workaround. Not all C code is portable. It's possible that the pecl extension has portability issues as it was probably intended to be run on linux. – Homer6 Dec 01 '11 at 12:47
  • 1
    @Homer6 Portability issues -- I guess you hit the nail on his head. I tried everything in order to make php-yaml work on MacOS, but without luck. So I go with sfYaml on my dev machine. – petabyte Dec 01 '11 at 17:08
  • Cool... I'll add an answer then. – Homer6 Dec 01 '11 at 21:41
1

Not all C code is portable. It's possible that the pecl extension has portability issues as it was probably intended to be run on linux.

If you're feeling bold, you could find out what the error is, fix it and submit the fix to the extension authors.

If not, then using a pure PHP solution might be the way to go.

Also, if you just run the code on your Mac as a dev environment, then you may not require it to work if: 1) production is linux or 2) the feature is not core to the functionality

However, in my experience, I find it's best to have your dev environments the same operating system and distro as your production box. I'd use VirtualBox to run linux in a VM, then map the files over SAMBA or NFS.

Hope that helps...

Homer6
  • 15,034
  • 11
  • 61
  • 81
  • I am sure it's a portability issue. I built several php extensions (no, this time yaml wasn't one of them ;) by simply setting some arch compiler flags -- they all work flawlessly with the PHP 5.3 version shipped with MAMP 1.9. – petabyte Dec 03 '11 at 21:26
0

Based on success overcoming issues surrounding MAMP and other .so modules: [Same type of error]

Step 1: Make sure your version of MAMP is Version 2 because it includes a Universal Binary installer (32-bit & 64-bit)

Step 2: Modify your Make file and eliminate the other compiler versions, similar to:

CFLAGS = -Wc,"-arch i386" -Wc,"-arch x86_64" -Wc ....
LDFLAGS = -arch i386 -arch x86_64 .....
Community
  • 1
  • 1
idea34
  • 713
  • 5
  • 10