Mac: PHP Startup: Unable to load dynamic library gettext

I’ve started today a new project in PHP on my Mac and started with the following error message in my php error log file:

[19-Jan-2014 10:39:14 UTC] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20100525/php_gettext.dll' – dlopen(/usr/lib/php/extensions/no-debug-non-zts-20100525/php_gettext.dll, 9): image not found in Unknown on line 0

So first you’ll notice it’s looking for a DLL on my Mac so obviously it won’t work. The first thing to check is php.ini:

$ grep extension= /etc/php.ini | grep -v "^;"
extension=php_gettext.dll

Ok so it’s really writte .dll in there. I’m not too sure whether I did it some time ago or whether it was installed like this. I’m pretty sure it used to work fine in the past since I was working on another project which didn’t have any problem with gettext. Inbetween I’ve upgraded to Mavericks but it might just be that I was working very late at night and modified php.ini on my Mac instead of doing it in my Windows virtual machine.

So I changed .dll to .so but without better results. Of course, I had checked the referenced extensions path first, I’d have seen that there are no files there except for xdebug.so.

So it looks like I’ll have to install php_gettext first. That’s not sp difficult.

First you need to find out which version of PHP is installed so that you can download the sources for this version:

$ php --version | head -1 | awk ' { print $2; } '
5.4.17

If you have a different version, you’ll need to change 5.4.17 to that version in all commands below.

Then create a working directory for building gettext for PHP:

mkdir /tmp/gettext
cd /tmp/gettext

Now we need to download the PHP sources and uncompress them:

curl --location --progress-bar http://museum.php.net/php5/php-5.4.17.tar.gz | tar -zx

Then we’ll install the latest version of gettext using Homebrew:

brew update
brew install gettext

Then we’ll prepare the PHP extension for compiling:

$ cd /tmp/gettext/php-5.4.17/ext/gettext/
$ phpize
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:        
Zend Module Api No:     
Zend Extension Api No:  

So something is missing. After a long search it seems I needed to install the command line developer tools:

$ xcode-select --install
xcode-select: note: install requested for command line developer tools

$ phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525

Now it looks better so we can continue, with configuring and building gettext (use the version number installed by brew instead of 0.18.3.2 in the command below):

$ ./configure --with-gettext=/usr/local/Cellar/gettext/0.18.3.2
...
$ make
...
----------------------------------------------------------------------
Libraries have been installed in:
   /tmp/gettext/php-5.4.17/ext/gettext/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
     during execution

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

So the shared library /tmp/gettext/php-5.4.17/ext/gettext/modules/gettext.so was created and we just need to copy it as php_gettext.so with:

$ sudo cp /tmp/gettext/php-5.4.17/ext/gettext/modules/gettext.so /usr/lib/php/extensions/no-debug-non-zts-20100525/php_gettext.so

And restart apache:

$ sudo /usr/sbin/apachectl restart

And now the error is gone ! You can now safely remove the directory /tmp/gettext.

One thought on “Mac: PHP Startup: Unable to load dynamic library gettext

Leave a Reply

Your email address will not be published. Required fields are marked *