Insights on Ruby, Git, jQuery, Cappuccino, WordPress, Debian and OS X. Please subscribe if you find something useful!

PHP5 with readline support on OS X

Posted: June 6th, 2009 | Author: Jerod | Filed under: OS X | Tags: , , | Comments

OS X ships with PHP5 installed but it does not have readline() support compiled in. Anybody using PHP from the command-line will want this, as it allows handy things such as tab completion and scrolling through command history using the up arrow.

Thankfully, MacPorts has a readline variant that can be easily installed:

sudo port install php5 +readline

If you execute the command above, apache2 will come along for the ride because it’s a default variant for the PHP5 port. If you don’t want apache2 (OS X ships with apache2 anyways), modify the command to look like this:

sudo port install php5 -apache2 +readline

Not sure if your PHP install has readline support? Execute this one-liner to find out:

<? echo function_exists('readline') ? "yes\n" : "no\n"; ?>