views:

595

answers:

2

I wrote a PHP extension, and I'm trying to get it running on Mac's Apache server.

It runs fine via the command line, for example:

$ php -r 'dl("mylib.dylib");

I also tried building Apache from source, and it works perfectly when I run that (I set it up to use the same PHP as Mac's built-in Apache, too, so no difference there).

However, when I load my extension with the default Apache you get using System Preferences->Web Sharing or, equivalently, apachectl in sbin, it says:

Warning: dl() [function.dl]: Unable to load dynamic library '/usr/lib/php/extensions/mylib.dylib' - (null) in /Users/myuname/Sites/test.php on line 6

Is there something weird about Mac's Apache or some permission for it that I have to set?

+2  A: 

This sounds like the sort of error that would be caused by architecture differences. Try doing a file /usr/lib/php/extensions/mylib.dylib and see which architectures are included in the binary. IIRC, Apache runs as 64-bit on Leopard, so you'll need to make sure that your library includes code for the 64-bit version of whichever processor you're running on (ppc64 or x86-64).

Chuck
Thank you, compiling it for 64-bit made it work perfectly!There were a bunch of 32-bit libraries that I hadn't realized it was depending on, so I had to recompile those, too, and then it worked.
kristina
A: 

Indeed, it's probably the 64-bit thing that's biting you in the arse. Try passing '-arch x86_64' to gcc when you compile your extension.

vasi