PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

PHP with Intl and Gettext on OSX Lion

Note: This article was originally published at Planet PHP on 7 August 2011.
Planet PHP

Mac OSX Lion ships with PHP 5.3.6. There are also other ways to get PHP working on Lion, for example:

These are all very good solutions, but since I prefer to travel light and the version in Lion already comes with a lot of useful extensions, I preferred to go with it.

Here is the list of extensions installed with Lion:

bcmath, bz2, calendar, Core, ctype, curl, date, dba, dom, ereg, exif, fileinfo, filter, ftp, gd, hash, iconv, json, ldap, libxml, mbstring, mysql, mysqli, mysqlnd, odbc, openssl, pcre, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, readline, Reflection, session, shmop, SimpleXML, snmp, soap, sockets, SPL, SQLite, sqlite3, standard, sysvmsg, sysvsem, sysvshm, tidy, tokenizer, wddx, xdebug, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, zlib

In /etc, there is a php.ini.default file that is not activated, so you will have to modify it to suit your preferences and rename it to /etc/php.ini. For instance, Lion also ships with Xdebug, but it is not activated by default. To activate it, you'll have to remove the semi-colon on the line that says:

zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

Lion doesn't provide neither PEAR nor PECL by default but it is easy to activate them because Apple provide the required php archive file (phar) for that:

cd /usr/lib/php sudo php install-pear-nozlib.phar

Then edit the php.ini file and add:

include_path = ".:/usr/lib/php/pear" extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20090626"

Then you can update your PEAR/PECL channels:

sudo pear channel-update pear.php.net sudo pecl channel-update pecl.php.net sudo pear upgrade-all

If like me you are missing the Intl extension, here is how I installed it (warning : requires Xcode):

  1. Download and install ICU tar xzvf icu4c-4_8_1-src.tgz cd icu/source ./runConfigureICU MacOSX make sudo make install
  2. Download PHP 5.3.6 sources
  3. Unpack
  4. Change directory to ext/intl
  5. Use the following commands in Terminal: cd ext/intl phpize ./configure --enable-intl make sudo cp modules/intl.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
  6. Activate intl in your php.ini file with extension=intl.so

Since I mostly work on multilingual sites, I also needed to install Gettext (it's unfortunate that Apple will not ship gettext and intl by default, a lot of PHP developers use more than Englisha). The problem is that Gettext apparently defines stpncpy function, as does something in Liona So I just renamed it to stpncpy2 in gettext-tools/gnulib-lib/stpncpy.c. This will probably break some stuff, but I don't care much on my dev machine:

tar xzvf gettext-0.18.1.1.tar.gz cd gettext-0.18.1.1 # edit gettext-tools/gnulib-lib/stpncpy.c ./configure make sudo make install

Then, back in the PHP sources directory:

cd ext/gettext phpize ./configure --with-gettext make sudo cp modules/gettext.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

And add this to the php.ini file:

extension=gettext.so

Finally I just restarted Apache from the Sharing Preference pane and I'm ready to start coding.