1

I have a brand new Mac, with Lion preinstalled. I enabled Apache, the PHP module.

phpinfo() works but there is no support for gettext.

Writing extension=php_gettext.so in php.ini did not help. So I tried to locate it in the filesystem, but it seems there are no PHP extensions available.

Where are PHP extensions in OS X Lion?

Francesco
  • 454
  • 1
  • 3
  • 12

4 Answers4

7

EDIT : Just tested and still works on Mavericks as long as you update MAMP with the latest version. Here is the full tutorial :

I managed to make it work using the gettext.so from MAMP with Mac OS X Apache/PHP native server. Here is how to so it :

  1. Download and install MAMP (pro not needed)
  2. Copy the MAMP gettext.so built for php 5.5.10 to Mavericks' local php extensions folder:

    sudo cp /Applications/MAMP/bin/php/php5.5.10/lib/php/extensions/no-debug-non-zts-20100525/gettext.so /usr/lib/php/extensions/no-debug-non-zts-20100525/

  3. Update Mavericks' /etc/php.ini file by adding this new line :

    extension=/usr/lib/php/extensions/no-debug-non-zts-20100525/gettext.so

  4. Restart apache :

    sudo apachectl restart

After that you can use _() and gettext() functions.

Thanks to @MountainAsh for noticing that we can't remove MAMP after this procedure since gettext uses one of MAMP libraries.

mbritto
  • 898
  • 12
  • 25
  • as of commenting step 3 changes to `sudo cp /Applications/MAMP/bin/php/php5.5.10/lib/php/extensions/no-debug-non-zts-20100525/gettext.so /usr/lib/php/extensions/no-debug-non-zts-20100525/` and step 5 is not possible (to uninstall) as gettext.so makes a call to `/Applications/MAMP/Library/lib/libiconv.2.dylib` on PHP load – MountainAsh Jun 25 '14 at 14:10
  • Further to my comments above, you can delete all from MAMP's 800+MB payload and just leave the following files and directory structure: `/Applications/MAMP/Library/lib/libiconv.2.dylib` & `/Applications/MAMP/Library/lib/libintl.8.dylib` which takes it down to 1.2 MB – MountainAsh Jun 25 '14 at 14:44
1

OS X so far does not include gettext (since my first attempt from 10.4). You'll have to build it yourself. I followed the process below and worked under 10.6 (taken from an Apple forum discussion thread). It's still working now in 10.7. Note that this is to install gettext module, not php_gettext. Though they function pretty much the some way, initialization supposedly is different. Remember though to swap the link for the right PHP version. I think 10.7 comes with PHP 5.3.6. You'll need to search for it.

Try this as root (or issue sudo -s before):


mkdir -p /SourceCache

cd /SourceCache

curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-0.17.tar.gz

tar xzf gettext-0.17.tar.gz

cd gettext-0.17

MACOSXDEPLOYMENTTARGET=10.6 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bindatload" ./configure

make

make install


cd /SourceCache

curl -O http://www.opensource.apple.com/source/apachemod_php/apache_modphp-53/php-5.3.0.tar.bz2

tar xjf php-5.3.0.tar.bz2

cd /SourceCache/php-5.3.0/ext/gettext

phpize

MACOSXDEPLOYMENTTARGET=10.6 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bindatload" ./configure

make

make install


When done, edit/create /etc/php.ini and add: extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/gettext.so

next issue: sudo apachectl graceful

Good luck!

T1000
  • 918
  • 2
  • 15
  • 30
  • As I told in the answer bellow, you can use the gettext.so from MAMP with Lion/Mountain Lion version of PHP. It's very simple and works like a charm for me – mbritto Aug 07 '12 at 13:28
  • For others dropping by: I've successfully built gettext-0.19.3 on a PowerPC based Mac running 10.5.8. make check fails with 'lang-bash', but apart from that, it installs fine. –  Nov 28 '14 at 16:13
0

For me, re-installing the current PHP version (5.5.29 on OS X 10.10.5 Yosemite) from http://php-osx.liip.ch was the easiest solution - no need to build my own gettext.so extension any more.

Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
0
/usr/lib/php/extensions/

You will find them here...

gettext does not seem to be included in Lion's version of PHP.

Macmade
  • 52,708
  • 13
  • 106
  • 123