Posted by Hill in Macintosh, Tutorials | 20 comments
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:
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
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
./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!!!!!!!!

If you get this, you get through, well, good luck!

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)
@ 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.bz2That was really helpful, thank you very much!
Herzliche Grüße
Thomas
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
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
@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?
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
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# ./configurechecking 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.
@Nepoc
thank you for providing the installation log.
and you can see that configuration stopped at this line:
config.status: config.h is unchangedSo 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" ./configuresudo make
sudo make install
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
@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.soI 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….
???
alx and jeremy
have you restarted you apache?
To enable the new configurations,apache must be restarted .
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
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.
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.”
Not working! I don’t know why?
I have a fresh OS X Leopard 10.5.2 install
There is only a php.ini.default but NO php.ini file.
huh?
@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.
Thanks!!! Work WELL with SLS 10.6.4!