PHP with Intl and Gettext on OSX Lion
Mac OSX Lion ships with PHP 5.3.6. There are also other ways to get PHP working on Lion, for example:
- Liip distributes a full featured PHP 5.3 binary for Lion
- Zend has its Zend Server Community Edition
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"
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):
- Download and install ICU tar xzvf icu4c-4_8_1-src.tgz cd icu/source ./runConfigureICU MacOSX make sudo make install
- Download PHP 5.3.6 sources
- Change directory to ext/intl
- 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/
- 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.