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)?
9 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.
- 1nup still no
php>prompt for me :(mulllhausen– mulllhausen2013-10-12 08:57:44 +00:00Commented Oct 12, 2013 at 8:57
After installing php5-cli from dotdeb, install the php5-readline package.
apt-get install php5-readline - This is only available in Jessie (testing) – packages.debian.org/…William Turrell– William Turrell2014-07-14 09:00:17 +00:00Commented Jul 14, 2014 at 9:00
- @williamt Thanks, I believe it is in the dotdeb repositories.cmc– cmc2014-07-14 13:24:54 +00:00Commented Jul 14, 2014 at 13:24
- The package
php5-readlineis available in the main archive of jessie and sid. And you don't need thephp5-clifrom dotdeb.Ortomala Lokni– Ortomala Lokni2015-03-06 07:33:48 +00:00Commented Mar 6, 2015 at 7:33
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 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 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.
- 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– Dziamid2012-08-01 09:47:53 +00:00Commented Aug 1, 2012 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– johannes2012-08-01 12:22:12 +00:00Commented Aug 1, 2012 at 12:22
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 -
rlwrapdoesn't seem to help much. When I runrlwrap php5, enterecho 1;, then hit return then Ctrl-D (end of input), it outputs the inputecho 1;instead of the result (1). Thanks for noting that it's a licensing issue.Matthew Flaschen– Matthew Flaschen2011-04-09 21:05:32 +00:00Commented Apr 9, 2011 at 21:05 - 3@Matthew: I don't know anything about PHP, but trying this on lenny, I see no difference between
rlwrap php5and justphp5, other than the former allowing command line edition. If you enter<?php echo 1;?>, the output is1, but it's not emitted immediately in either case. Googling suggests thatphp5simply isn't a PHP REPL, and you should use something like phpsh instead.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2011-04-09 21:42:32 +00:00Commented Apr 9, 2011 at 21:42 - 1you don't enter the
<?phpor?>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– Matthew Flaschen2011-04-09 21:49:16 +00:00Commented Apr 9, 2011 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 'SO- stop being evil'– Gilles 'SO- stop being evil'2011-04-09 21:54:52 +00:00Commented Apr 9, 2011 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– Matthew Flaschen2011-04-09 22:00:13 +00:00Commented Apr 9, 2011 at 22:00
Try this:
$ php -a Interactive mode enabled <?php echo "hi!"; ?> The press Ctrl-d
- 5This doesn't seem like it has anything to do with installing PHPMichael Mrozek– Michael Mrozek2011-05-20 10:21:06 +00:00Commented May 20, 2011 at 10:21
- 1This 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– Matthew Flaschen2011-05-24 18:39:36 +00:00Commented May 24, 2011 at 18:39
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.
In debian jessie and in debian sid use:
sudo apt-get install php5 php5-readline then
php -a Interactive mode enabled php > echo 1+2; 3 php > As simple as sudo apt install php7.2-cli
[lucas:~] 20s 130 % sudo apt install php7.2-cli Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libavdevice57 libegl-mesa0:i386 libegl1:i386 libgbm1:i386 libgsasl7 libkyotocabinet16v5 libmailutils5 libmemcached11 libntlm0 libwayland-egl1-mesa:i386 libwayland-server0:i386 mailutils-common mysql-client-core-5.7 shim ttf-dejavu-core webhttrack-common Use 'sudo apt autoremove' to remove them. Suggested packages: php-pear The following NEW packages will be installed: php7.2-cli 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 1.407 kB of archives. After this operation, 4.956 kB of additional disk space will be used. Get:1 http://br.archive.ubuntu.com/ubuntu bionic-updates/main amd64 php7.2-cli amd64 7.2.24-0ubuntu0.18.04.4 [1.407 kB] Fetched 1.407 kB in 0s (6.666 kB/s) Selecting previously unselected package php7.2-cli. (Reading database ... 320578 files and directories currently installed.) Preparing to unpack .../php7.2-cli_7.2.24-0ubuntu0.18.04.4_amd64.deb ... Unpacking php7.2-cli (7.2.24-0ubuntu0.18.04.4) ... Setting up php7.2-cli (7.2.24-0ubuntu0.18.04.4) ... update-alternatives: using /usr/bin/php7.2 to provide /usr/bin/php (php) in auto mode update-alternatives: using /usr/bin/phar7.2 to provide /usr/bin/phar (phar) in auto mode update-alternatives: using /usr/bin/phar.phar7.2 to provide /usr/bin/phar.phar (phar.phar) in auto mode Processing triggers for man-db (2.8.3-2ubuntu0.1) ... [lucas:~] % php --version PHP 7.2.24-0ubuntu0.18.04.4 (cli) (built: Apr 8 2020 15:45:57) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.24-0ubuntu0.18.04.4, Copyright (c) 1999-2018, by Zend Technologies [lucas:~] % php -a Interactive mode enabled php > Of course, this is PHP CLI only. It allows you to run Composer and all things CLI. It does not include a web server such as Apache or Nginx.