Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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)?

share|improve this question
add comment

6 Answers

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

as root.

share|improve this answer
    
nup still no php> prompt for me :( –  mulllhausen Oct 12 '13 at 8:57
add comment

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 realdine functionality that all required parts are in the readline module, so you can built 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 loaed from php.ini (make install will move it to extension_dir)

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 stillbe interesting. A little information is in the bug report #53878 but not much either ... after release http://php.net/commandline.interactive should have more.

share|improve this answer
    
Thanks, that helped. Encountered 2 problem on Ubuntu, however. Was missing libedit library (fixed by installing libedit-dev) and this compilation bug ocurred: bugs.php.net/bug.php?id=62612 Solution is there as well. –  Dziamid Aug 1 '12 at 9:47
    
Funny how I contradict myself! here I suggest phpize etc. in the bug I say it's not "fully" supported to do so ;-) –  johannes Aug 1 '12 at 12:22
add comment

Install 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
share|improve this answer
    
rlwrap doesn't seem to help much. When I run rlwrap php5, enter echo 1;, then hit return then Ctrl-D (end of input), it outputs the input echo 1; instead of the result (1). Thanks for noting that it's a licensing issue. –  Matthew Flaschen Apr 9 '11 at 21:05
3  
@Matthew: I don't know anything about PHP, but trying this on lenny, I see no difference between rlwrap php5 and just php5, other than the former allowing command line edition. If you enter <?php echo 1;?>, the output is 1, but it's not emitted immediately in either case. Googling suggests that php5 simply isn't a PHP REPL, and you should use something like phpsh instead. –  Gilles Apr 9 '11 at 21:42
1  
you don't enter the <?php or ?> in the interactive shell. I agree that php doesn't have a full REPL. But using a version compiled with with working readline support (e.g. the dotdeb package I linked), it will output 1 (or whatever the real output is) immediately after you press enter. I agree there's no significant difference between rlwrap and no readline at all (besides line-editing and history, which are nice but not as useful as immediate output). –  Matthew Flaschen Apr 9 '11 at 21:49
    
@Matthew: Ah, so readline support does more than just link with readline, it also changes the behavior of the program? That seems weird. Then you can rebuild from source, or use the dotdeb packages if they work for you. –  Gilles Apr 9 '11 at 21:54
    
yeah, a lot of things in PHP seem weird. ;) But it does look like the readline code path is different in this area only tangentially related to readline. –  Matthew Flaschen Apr 9 '11 at 22:00
add comment

Try this:

$ php -a
Interactive mode enabled

<?php echo "hi!"; ?>

The press Ctrl-d

share|improve this answer
2  
This doesn't seem like it has anything to do with installing PHP –  Michael Mrozek May 20 '11 at 10:21
    
This is actually very helpful, even though it doesn't directly answer the question. It shows that in the non-readline path, PHP only executes PHP code inside <?php ?> blocks. I wasn't aware of that, and it shows I misunderstood Gilles earlier. –  Matthew Flaschen May 24 '11 at 18:39
add comment

None of these worked for me. Use http://www.phpsh.org/ instead.

share|improve this answer
add comment

After installing php5-cli, install the php5-readline package.

apt-get install php5-readline
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.