简体   繁体   中英

Install YAML Pecl PHP Extension on MAMP

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 ie "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

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.

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: :)

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...

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 .....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM