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:
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):
- 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 (update: I tried with 5.3.8, I got a compilation error, so use 5.3.6)
- Change directory to
- 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
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 English, but that might be another licence issue…). The problem is that Gettext apparently defines
stpncpy function, as does something in Lion…
tar xzvf gettext-0.18.1.1.tar.gz cd gettext-0.18.1.1 # apply patch here, then : ./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:
Finally I just restarted Apache from the Sharing Preference pane and I’m ready to start coding.
Updates 02/24/2012: Don’t use 5.3.8. Use the patch suggested in the comments for Gettext to compile.