When I install php5-cli on Debian Wheezy (currently testing), the interactive prompt is very unusable due to missing readline support (bug 341868). What's the easiest way to install a version linked against libreadline (for usable line editing)?
Use the Dotdeb Debian stable packages. Although the documentation does not note this, the stable packages currently work fine with Wheezy/testing. After following the instructions, do:
apt-get install php5-cli
After installing php5-cli from dotdeb, install the php5-readline package.
apt-get install php5-readline
As an addition to the answer by Gilles who suggest recompiling the complete PHP package you can also wait for PHP 5.4. In 5.4 I restructured the readline functionality that all required parts are in the readline module, so you can build that stand alone.
$ wget ...php-5.4.0.tar.bz2 $ tar xjf php-5.4.0.tar.bz2 $ cd php-5.4.0/ext/readline $ phpize && ./configure && make
Then you will end up with a
modules/readline.so which can be loaded from php.ini (
make install will move it to
Alternatively the distributor may ship the readline module (maybe linked against libedit, not readline) and the interactive mode will be available.
This all won't help you now (as PHP 5.4. isn't out, yet) but might help others finding this question later.
Some more details on my blog: http://schlueters.de/blog/archives/133-Now-in-trunk-Improved-interactive-shell.html
Edit: Actually the blog post is older than this change, but might still be interesting. A little information is in the bug report #53878 but not much either ... after release http://php.net/commandline.interactive should have more.
rlwrap and run
rlwrap php5. Rlwrap is a generic readline wrapper, it provides command line edition and history for any read-eval-print loop. Since it's a generic wrapper, you won't get any PHP-specific completion.
Alternatively, get the source package and rebuild it with readline support. Readline support was only left out due to licensing issues, but these issues only forbid distributing PHP5 linked with readline, they don't forbid you from using it.
apt-get source php5-cli apt-get install build-essential fakeroot apt-get build-dep php5-cli cd php5-*/ # Edit debian/rules to configure with readline support # Add an entry to debian/changelog to remember what you did dpkg-buildpackage -rfakeroot -us -uc -b -nc
$ php -a Interactive mode enabled <?php echo "hi!"; ?>
The press Ctrl-d
For Ubuntu users, php5-readline is the additional package you need to install to have a usable php command prompt:
sudo apt-get install php5-cli php5-readline sudo php5enmod readline
I had to do this on my Ubuntu 14.04.
None of these worked for me. Use http://www.phpsh.org/ instead.
In debian jessie and in debian sid use:
sudo apt-get install php5 php5-readline
php -a Interactive mode enabled php > echo 1+2; 3 php >