Adding Gettext Extension for Mac OS X Leopard

I just installed a Gallery2 in this hosting and I just wanted to install a test gallery in my local Mac for testing and developing themes, but unfortunately, The PHP5 pre-installed in Leopard has not GD library and gettext enabled (or means installed). The tutorial of installation of GD library for Leopard can be found in Alex’s site: Adding the GD Extension to PHP5 on OS X Server 10.5.x. And next, I’ll tell you how to enable gettext extension for leopard’s PHP5.

Well… let’s go!

1.Requirements

  • You have made a backup of your system.
  • You have the latest version of Apple’s Developer Tools (XCode 3.0 or higher for 10.5.x) installed. Dev Tools are available on your Server DVD and as a free download from Apple’s Developer Connection.
  • X11 is installed (part of standard OS X Server install unless you deselect it)
  • X11 SDK is installed (available on your OS X Developer Tools Disc or Image and part of the standard installation. This is different from the X11 client that comes with OS X.)
  • You do have a backup
  • You are running 10.5.x
  • You have not manually installed (or updated) anything related to gettext, if you have, you must know how to adapt these instructions to the changes you made.

2. Getting gettext and Installing gettext-runtime.
Open your Terminal and type:
For 32-bit :

mkdir -p /SourceCache
cd /SourceCache
curl -O ftp://ftp.gnu.org/gnu/gettext/gettext-0.17.tar.gz
tar xzpf gettext-0.17.tar.gz
cd /SourceCache/gettext-0.17/gettext-runtime
./configure
sudo make
sudo make install

For 64-bit :

mkdir -p /SourceCache
cd /SourceCache
curl -O ftp://ftp.gnu.org/gnu/gettext/gettext-0.17.tar.gz
tar xzpf gettext-0.17.tar.gz
cd /SourceCache/gettext-0.17/gettext-runtime
MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe -no-cpp-precomp" CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe" CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe" LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load" ./configure --enable-shared
sudo make
sudo make install

Now, libintl.h has been installed in your /usr/local/include. gettext cannot be installed if we have not libintl.h located in our Mac.

3. Installation of gettext
Download PHP-5.2.4 (or php-5.2.5) source code in PHP official site. or you can download it by using your Terminal.

cd /SourceCache
curl -O http://www.opensource.apple.com/darwinsource/10.5/apache_mod_php-43/php-5.2.4.tar.bz2
tar xjf php-5.2.4.tar.bz2
cd /SourceCache/php-5.2.4/ext/gettext
sudo phpize

Then,For 32-bit:
./configure
sudo make
sudo make install

For 64-bit use:

MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe -no-cpp-precomp" CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe" CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe" LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load" ./configure
sudo make
sudo make install

4. Integration of gettext and PHP
Go to /etc and edit php.ini with your favorite editor (I like BBEdit). and add this line:
extension=gettext.so
and search this line in php.ini (VERY IMPORTANT)
extension_dir = "./"
Disable this line if this line is uncommented, just add a semicolon in front of this line.

5. Testing…
Create a phptest.php file with the following code:
<?php
phpinfo();
?>

and save it in /Library/WebServer/Documents.
then, restart Apache and test
Open System Preference → Sharing and check the “web sharing” option
and visit http://127.0.0.1/phptest.php

Bravo!!!!!!!!
gettext info
If you get this, you get through, well, good luck!

24 comments so far

  1. Mrdk December 20, 2007 9:37

    Thanks, good job!

    But “tar xzpf php-5.2.4.tar.bz2″ dosn’t work.
    you cannot open bz2-files with gzip - so you have to use bzip2

    How to:
    1. (bzip2 -d php-5.2.4.tar.bz2)
    2. (tar xvfpz php-5.2.4.tar)

  2. Hill December 20, 2007 18:42

    @ Mrdk
    Thank you for pointing out my mistake.
    I have modified my command line and I have tested.
    it could be like this:
    tar xjf php-5.2.4.tar.bz2

  3. Thomas Gutzmann January 17, 2008 0:12

    That was really helpful, thank you very much!

    Herzliche Grüße

    Thomas

  4. Michael January 21, 2008 3:54

    Hello, great guide!! but I ran into a problem. I think I did everything right, but I get the following error in the error_log and gettext is not loading:

    PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/extensions/no-debug-non-zts-20060613/gettext.so’ - (null) in Unknown on line 0
    [Sun Jan 20 17:46:17 2008] [notice] Apache/2.2.6 (Unix) mod_ssl/2.2.6 OpenSSL/0.9.7l PHP/5.2.4 configured — resuming normal operations
    :( what did I do?

  5. Nepoc January 26, 2008 0:58

    Hello,

    I too am having this problem:
    PHP Warning: PHP Startup: Unable to load dynamic library ‘./gettext.so’ - (null) in Unknown on line 0
    [Fri Jan 25 15:54:09 2008] [notice] Apache/2.2.6 (Unix) mod_ssl/2.2.6 OpenSSL/0.9.7l PHP/5.2.4 configured — resuming normal operations

    The only difference was I placed gettext.so in /usr/lib/php/extensions and kept the extensions_dir = “./” just as a note I did try the suggested way the first time.

    Any help would be greatly appreciated.

    Thank you

  6. Hill January 26, 2008 23:16

    @Nepoc

    You have to keep this line (extensions_dir = “./”)enabled?
    normally, that you put gettext in /usr/lib/php/extensions will not cause any problem if you disable that line.
    I mean, if you disable that line in your php.ini file, system will search gettext.so under /usr/lib/php/extensions. but if you enabled “extensions_dir =”./”", php system will lost its mind. Alex has pointed out that you can customized extension dictionary.
    you said you have tried to disable that line the first time, and what kind of error it caused?

  7. Nepoc January 28, 2008 23:44

    Thank you for the response.

    Let me explain what I’ve done so far.

    When I have ;extensions_dir = “./” and extension=gettext.so in php.ini and /usr/lib/php/extensions/no-debug-non-zts-20060613/gettext.so

    When starting web the error_log shows:
    PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/extensions/no-debug-non-zts-20060613/gettext.so’ - (null) in Unknown on line 0
    [Mon Jan 28 14:34:41 2008] [notice] Apache/2.2.6 (Unix) mod_ssl/2.2.6 OpenSSL/0.9.7l PHP/5.2.4 configured — resuming normal operations

    When I have extensions_dir = “./” and extension=gettext.so in php.ini and /usr/lib/php/extensions/gettext.so

    When starting web the error_log shows:
    PHP Warning: PHP Startup: Unable to load dynamic library ‘./gettext.so’ - (null) in Unknown on line 0
    [Mon Jan 28 14:42:05 2008] [notice] Apache/2.2.6 (Unix) mod_ssl/2.2.6 OpenSSL/0.9.7l PHP/5.2.4 configured — resuming normal operations

    I’m assuming it just can’t find the file but I’m not sure.

    Let me know if you have any suggestions.

    Cheers

  8. Nepoc January 29, 2008 0:39

    Little more info, I tried to rebuild the gettext extension and I have some things that don’t look quite right.

    Here’s the output.

    gettext root# ./configure
    checking for grep that handles long lines and -e... /usr/bin/grep
    checking for egrep... /usr/bin/grep -E
    checking for a sed that does not truncate output... /usr/bin/sed
    checking for gcc... gcc
    checking for C compiler default output file name... a.out
    checking whether the C compiler works... yes
    checking whether we are cross compiling... no
    checking for suffix of executables...
    checking for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether gcc accepts -g... yes
    checking for gcc option to accept ISO C89... none needed
    checking whether gcc and cc understand -c and -o together... yes
    checking for system library directory... lib
    checking if compiler supports -R... no
    checking if compiler supports -Wl,-rpath,... yes
    checking build system type... powerpc-apple-darwin9.1.0
    checking host system type... powerpc-apple-darwin9.1.0
    checking target system type... powerpc-apple-darwin9.1.0
    checking for PHP prefix... /usr
    checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
    checking for PHP extension directory... /usr/lib/php/extensions/no-debug-non-zts-20060613
    checking for PHP installed headers prefix... /usr/include/php
    checking for re2c... no
    configure: WARNING: You will need re2c 0.12.0 or later if you want to regenerate PHP parsers.
    checking for gawk... no
    checking for nawk... no
    checking for awk... awk
    checking if awk is broken... no
    checking for GNU gettext support... yes, shared
    checking for bindtextdomain in -lintl... yes
    checking for ngettext in -lintl... yes
    checking for dngettext in -lintl... yes
    checking for dcngettext in -lintl... yes
    checking for bind_textdomain_codeset in -lintl... yes
    checking for ld used by gcc... /usr/libexec/gcc/powerpc-apple-darwin9/4.0.1/ld
    checking if the linker (/usr/libexec/gcc/powerpc-apple-darwin9/4.0.1/ld) is GNU ld... no
    checking for /usr/libexec/gcc/powerpc-apple-darwin9/4.0.1/ld option to reload object files... -r
    checking for BSD-compatible nm... /usr/bin/nm -p
    checking whether ln -s works... yes
    checking how to recognise dependent libraries... pass_all
    checking how to run the C preprocessor... gcc -E
    checking for ANSI C header files... rm: conftest.dSYM: is a directory
    rm: conftest.dSYM: is a directory
    yes
    checking for sys/types.h... yes
    checking for sys/stat.h... yes
    checking for stdlib.h... yes
    checking for string.h... yes
    checking for memory.h... yes
    checking for strings.h... yes
    checking for inttypes.h... yes
    checking for stdint.h... yes
    checking for unistd.h... yes
    checking dlfcn.h usability... yes
    checking dlfcn.h presence... yes
    checking for dlfcn.h... yes
    checking the maximum length of command line arguments... 196608
    checking command to parse /usr/bin/nm -p output from gcc object... rm: conftest.dSYM: is a directory
    rm: conftest.dSYM: is a directory
    rm: conftest.dSYM: is a directory
    rm: conftest.dSYM: is a directory
    ok
    checking for objdir... .libs
    checking for ar... ar
    checking for ranlib... ranlib
    checking for strip... strip
    rm: conftest.dSYM: is a directory
    rm: conftest.dSYM: is a directory
    checking if gcc static flag  works... rm: conftest.dSYM: is a directory
    yes
    checking if gcc supports -fno-rtti -fno-exceptions... rm: conftest.dSYM: is a directory
    no
    checking for gcc option to produce PIC... -fno-common
    checking if gcc PIC flag -fno-common works... rm: conftest.dSYM: is a directory
    yes
    checking if gcc supports -c -o file.o... rm: conftest.dSYM: is a directory
    yes
    checking whether the gcc linker (/usr/libexec/gcc/powerpc-apple-darwin9/4.0.1/ld) supports shared libraries... yes
    checking dynamic linker characteristics... darwin9.1.0 dyld
    checking how to hardcode library paths into programs... immediate
    checking whether stripping libraries is possible... yes
    checking if libtool supports shared libraries... yes
    checking whether to build shared libraries... yes
    checking whether to build static libraries... no
    #
    creating libtool
    appending configuration tag "CXX" to libtool
    configure: creating ./config.status
    config.status: creating config.h
    config.status: config.h is unchanged

    There are a few things I thought didn’t look quite right. Mainly all the rm errors.

    Hopefully that is helpful to find a solution for me.

  9. Hill January 29, 2008 14:47

    @Nepoc
    thank you for providing the installation log.
    and you can see that configuration stopped at this line:
    config.status: config.h is unchanged
    So I have a question: Is your machine is 64 bit?
    if this is the case, uncompress gettext zip package again and run “make clean” command first. And then check this article http://www.veola.net/macintosh/adding-gd-library-for-mac-os-x-leopard
    this article is for installing GD library but the part of the command line for 64 bit is same.

    MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe -no-cpp-precomp" CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe" CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe" LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load" ./configure
    sudo make
    sudo make install
  10. Alx February 5, 2008 21:21

    Hey there,

    first off thx for the tutorial, unfortunately I fall in a worse case than the one stated above :/

    Since I already had libint.h, I started at step 3.
    phpize works
    configure works
    make works
    make test fails on both tests (don’t what those tests actually do though…)
    make install works (says it copies to [...]/extenions/no-debug-non-zts-20060613)
    tried both combinations as Nepoc did (commenting and uncommenting etc.). Apache would start without error message (so I’m thinking hurray), but the phpinfo() function does not show any gettext extension… And for sure it isn’t there cuz my script calling bindtextdomain still doesn’t find it !

    Any other clue ?
    I can give more info if u need

    thx a bunch !

    alx

  11. hill February 7, 2008 2:36

    @alx
    thank you for your reply, but I don’t know why your php doesn’t run gettext.

    phpize works
    make works
    make test(you don’t need do it)
    make install works

    and apache works

    and i have a question: Did you add this line in your php.ini file?extension=gettext.so

  12. Jeremy Toaster February 12, 2008 17:20

    I have the same issue. OS X 10.5 did all the installs for gd library and gettext, everything installed with NO errors, went to the /usr/lib/php/extensions/no-debug-non-zts-20060613/ folder and everything is there.

    ; Directory in which the loadable extensions (modules) reside.
    ;extension_dir = “./”

    ; Enable gd extension module
    extension=gd.so

    ; Enable GetText extension module
    extension=gettext.so

    Also tried this both ways…
    ;extension=php_fdf.dll
    ;extension=php_gd2.dll
    ;extension=php_gettext.dll
    ;extension=php_gmp.dll

    ;extension=php_fdf.dll
    extension=php_gd2.dll
    extension=php_gettext.dll
    ;extension=php_gmp.dll

    Makes no difference, get NO errors, but neither one shows up in the info.php file….

    ???

  13. HILL February 14, 2008 13:06

    alx and jeremy
    have you restarted you apache?
    To enable the new configurations,apache must be restarted .

  14. Pandora February 15, 2008 9:41

    Have the same error. Installation works, apache restarts with no error but neither gd nor gettext shows off in the info.php file also my web applications cannot use it

  15. Nebur February 18, 2008 15:30

    To get thing to work on 10.5 I had to add the

    MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp” CCFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe” LDFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load” ./configure

    To both the gettext and the php steps.

    In my /etc/php.ini I have not commented out the
    extensions_dir = “./”
    directive.

    After a “apachectl restart”, then everything works fine.

  16. Richard March 22, 2008 7:06

    I noticed you go right from “make” to “make install” without a “make check.” You have more guts than me, mon ami.

    On my Leopard box, for example, gettext compiles without incident, but fails more tests than it passes on a “make check.”

  17. AtlasWu April 16, 2008 6:52

    Not working! I don’t know why?

  18. kenior April 25, 2008 18:45

    @scott

    There’s no php.ini file by default. so waht you have to do is reanming the php.ini.default to be php.ini

    @Richard

    yes you are right. I didn’t make check but there’s no issue without doing that step.

  19. Ivan X May 4, 2008 16:03

    This all worked great for me on my MacBook Core 2 Duo (64-bit), but only after I used the longer ./configure mentioned for both gettext and php. I suggest that you modify the original post, because I followed the instructions to the letter and it didn’t work until I found the 64-bit instructions in the comments. Thanks for putting this up, I never would have figured it out.

  20. Bill June 12, 2008 16:35

    I just tried these instructions on Leopard (client) and they worked great. I then followed the instructions on Leopard Server and they don’t work. I did everything the same, but I do not get gettext support listed when I do a phpinfo!

  21. Bill June 12, 2008 17:11

    Well, I feel like a fool. I was using a 64 bit machine and didn’t realize it. :) All is well.

  22. Ajia July 23, 2008 21:27

    I am working on moving my working l10n web site from Linux machine to Mac OS X 10.5.2. I am glad to see this instruction. But while I was trying to “make” php 5.2.5, it failed. It seems the compiling directory has problem. Hope I will get some help from here too. I got:
    —————————————————
    Macintosh-6:gettext admin$ sudo make
    /bin/sh /SourceCache/php-5.2.5/ext/gettext/libtool –mode=compile gcc -I. -I/SourceCache/php-5.2.5/ext/gettext -DPHP_ATOM_INC -I/SourceCache/php-5.2.5/ext/gettext/include -I/SourceCache/php-5.2.5/ext/gettext/main -I/SourceCache/php-5.2.5/ext/gettext -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /SourceCache/php-5.2.5/ext/gettext/gettext.c -o gettext.lo
    mkdir .libs
    gcc -I. -I/SourceCache/php-5.2.5/ext/gettext -DPHP_ATOM_INC -I/SourceCache/php-5.2.5/ext/gettext/include -I/SourceCache/php-5.2.5/ext/gettext/main -I/SourceCache/php-5.2.5/ext/gettext -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /SourceCache/php-5.2.5/ext/gettext/gettext.c -fno-common -DPIC -o .libs/gettext.o
    /SourceCache/php-5.2.5/ext/gettext/gettext.c:35: error: syntax error before numeric constant
    ……
    /SourceCache/php-5.2.5/ext/gettext/gettext.c:41: error: storage class specified for parameter ‘ZEND_BEGIN_ARG_INFO’
    In file included from /SourceCache/php-5.2.5/ext/gettext/gettext.c:128:
    …… ( a lot more)
    make: *** [gettext.lo] Error 1

  23. AngelHide August 5, 2008 13:40

    Thank you for this, but it doesn’t work for me.
    I tried to make it work on leopard 10.5.4 Server.

  24. Pedro August 17, 2008 23:14

    Hy! I saw a blog where they explained how install GD library on leopard. Here http://www.fernandoalou.com/blog/archivo/2008/08/14/7/instalar-la-libreria-gd-en-leopard/

Leave a comment

Please be polite and on topic. Your e-mail will never be published.

powered by wordpress hosted by WHB