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.

php5-cli does not come with readline support on debian wheezy. this means that the interactive php shell (run as $ php -a) does not have a prompt (php >), instead it just says Interactive mode enabled and then leaves the cursor on a blank line. i can execute php but it is awkward, eg <? echo 'hi'; ?> enterctrld and it will excute a php command, but this is no way near as nice as having the prompt with readline support.

I found some instructions to install php5-cli with readline support via the dotdeb repository however i get half way and it gives an error:

download GPG key

$ cd /tmp
$ wget http://www.dotdeb.org/dotdeb.gpg
--2013-10-13 00:12:27--  http://www.dotdeb.org/dotdeb.gpg
Resolving www.dotdeb.org (www.dotdeb.org)... 88.190.17.153
Connecting to www.dotdeb.org (www.dotdeb.org)|88.190.17.153|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5299 (5.2K) [application/octet-stream]
Saving to: `dotdeb.gpg'

100%[=====================================================================================>] 5,299       --.-K/s   in 0.005s  

2013-10-13 00:12:28 (946 KB/s) - `dotdeb.gpg' saved [5299/5299]

Install GPG key

$ cat dotdeb.gpg | sudo apt-key add -
OK
$ sudo apt-get update
Ign cdrom://[Debian GNU/Linux 7.0.0 _Wheezy_ - Official Snapshot amd64 LIVE/INSTALL Binary 20130505-10:47] wheezy Release.gpg
Ign cdrom://[Debian GNU/Linux 7.0.0 _Wheezy_ - Official Snapshot amd64 LIVE/INSTALL Binary 20130505-10:47] wheezy Release
Ign cdrom://[Debian GNU/Linux 7.0.0 _Wheezy_ - Official Snapshot amd64 LIVE/INSTALL Binary 20130505-10:47] wheezy/main amd64 Packages/DiffIndex
Ign cdrom://[Debian GNU/Linux 7.0.0 _Wheezy_ - Official Snapshot amd64 LIVE/INSTALL Binary 20130505-10:47] wheezy/main Translation-en_AU
Ign cdrom://[Debian GNU/Linux 7.0.0 _Wheezy_ - Official Snapshot amd64 LIVE/INSTALL Binary 20130505-10:47] wheezy/main Translation-en
Hit http://ftp.au.debian.org wheezy Release.gpg                                                              
Hit http://ftp.au.debian.org wheezy-updates Release.gpg                                                      
Hit http://ftp.au.debian.org wheezy Release                                                                  
Hit http://ftp.au.debian.org wheezy-updates Release                                                                           
Hit http://ftp.au.debian.org wheezy/main Sources                                                                              
Hit http://ftp.au.debian.org wheezy/main amd64 Packages                                                                       
Hit http://ftp.au.debian.org wheezy/main Translation-en                                                      
Hit http://ftp.au.debian.org wheezy-updates/main Sources                       
Hit http://ftp.au.debian.org wheezy-updates/main amd64 Packages/DiffIndex
Hit http://ftp.au.debian.org wheezy-updates/main Translation-en/DiffIndex
Hit http://packages.dotdeb.org wheezy Release.gpg
Hit http://security.debian.org wheezy/updates Release.gpg
Hit http://packages.dotdeb.org wheezy Release
Hit http://security.debian.org wheezy/updates Release
Hit http://packages.dotdeb.org wheezy/all Sources
Hit http://packages.dotdeb.org wheezy/all amd64 Packages
Hit http://security.debian.org wheezy/updates/main Sources
Hit http://security.debian.org wheezy/updates/main amd64 Packages
Hit http://security.debian.org wheezy/updates/main Translation-en
Ign http://packages.dotdeb.org wheezy/all Translation-en_AU
Ign http://packages.dotdeb.org wheezy/all Translation-en
Reading package lists... Done

dist-upgrade

$ sudo apt-get dist-upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Test PHP in interactive mode

$ php -a
Interactive mode enabled

<?php echo 'hi'; ?>
hi$ # this is not what i want!

Try compiling readline support

$ sudo aptitude install php5-dev libedit-dev
No packages will be installed, upgraded, or removed.
0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B of archives. After unpacking 0 B will be used.

$ cd ~/
$ sudo apt-get source php5-cli
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Picking 'php5' as source package instead of 'php5-cli'
NOTICE: 'php5' packaging is maintained in the 'Git' version control system at:
git://git.debian.org/pkg-php/php.git
Need to get 11.8 MB of source archives.
Get:1 http://packages.dotdeb.org/ wheezy/all php5 5.4.20-1~dotdeb.1 (dsc) [3,425 B]
Get:2 http://packages.dotdeb.org/ wheezy/all php5 5.4.20-1~dotdeb.1 (tar) [11.7 MB]
Get:3 http://packages.dotdeb.org/ wheezy/all php5 5.4.20-1~dotdeb.1 (diff) [121 kB]                                           
Fetched 11.8 MB in 31s (374 kB/s)                                                                                             
dpkg-source: warning: extracting unsigned source package (php5_5.4.20-1~dotdeb.1.dsc)
dpkg-source: info: extracting php5 in php5-5.4.20
dpkg-source: info: unpacking php5_5.4.20.orig.tar.bz2
dpkg-source: info: unpacking php5_5.4.20-1~dotdeb.1.debian.tar.gz
dpkg-source: info: applying 001-libtool_fixes.patch
dpkg-source: info: applying 006-debian_quirks.patch
dpkg-source: info: applying libtool2.2.patch
dpkg-source: info: applying 019-z_off_t_as_long.patch
dpkg-source: info: applying 033-we_WANT_libtool.patch
dpkg-source: info: applying 052-phpinfo_no_configure.patch
dpkg-source: info: applying 053-extension_api.patch
dpkg-source: info: applying 054-phpinfo_dotdeb.patch
dpkg-source: info: applying 057-no_apache_installed.patch
dpkg-source: info: applying 100-recode_is_shared.patch
dpkg-source: info: applying 113-php.ini_securitynotes.patch
dpkg-source: info: applying sybase-alias.patch
dpkg-source: info: applying qdbm-is-usr_include_qdbm.patch
dpkg-source: info: applying session_save_path.patch
dpkg-source: info: applying php-fpm-man-section-and-cleanup.patch
dpkg-source: info: applying fpm-config.patch
dpkg-source: info: applying php-fpm-sysconfdir.patch
dpkg-source: info: applying temporary-path-fixes-for-multiarch.patch
dpkg-source: info: applying php-5.3.9-mysqlnd.patch
dpkg-source: info: applying php-fpm-listen-on-unix-socket.patch

$ cd php5-5.4.20/ext/readline
$ pwd
/home/peter/php5-5.4.20/ext/readline
$ ls
config.m4  CREDITS  php_readline.h  readline.c  readline_cli.c  readline_cli.h  README.libedit  tests

Run phpize

$ sudo phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525

$ pwd
/home/peter/php5-5.4.20/ext/readline

$ ls
acinclude.m4    build         config.m4   configure.in  ltmain.sh        mkinstalldirs   readline_cli.c  run-tests.php
aclocal.m4      config.guess  config.sub  CREDITS       Makefile.global  php_readline.h  readline_cli.h  tests
autom4te.cache  config.h.in   configure   install-sh    missing          readline.c      README.libedit

Configure

$ sudo ./configure 
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib
checking for PHP extension directory... /usr/lib/php5/20100525
checking for PHP installed headers prefix... /usr/include/php5
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 0.13.5 (ok)
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for libedit readline replacement... yes, shared
checking for tgetent in -lncurses... no
checking for tgetent in -ltermcap... yes
checking for readline in -ledit... yes
checking for rl_callback_read_char in -ledit... yes
checking for rl_on_new_line in -ledit... no
checking for rl_completion_matches... no
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) nawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands

Make

$ sudo make
/bin/bash /home/peter/php5-5.4.20/ext/readline/libtool --mode=compile cc  -I. -I/home/peter/php5-5.4.20/ext/readline -DPHP_ATOM_INC -I/home/peter/php5-5.4.20/ext/readline/include -I/home/peter/php5-5.4.20/ext/readline/main -I/home/peter/php5-5.4.20/ext/readline -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /home/peter/php5-5.4.20/ext/readline/readline.c -o readline.lo 
libtool: compile:  cc -I. -I/home/peter/php5-5.4.20/ext/readline -DPHP_ATOM_INC -I/home/peter/php5-5.4.20/ext/readline/include -I/home/peter/php5-5.4.20/ext/readline/main -I/home/peter/php5-5.4.20/ext/readline -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/peter/php5-5.4.20/ext/readline/readline.c  -fPIC -DPIC -o .libs/readline.o
/bin/bash /home/peter/php5-5.4.20/ext/readline/libtool --mode=compile cc  -I. -I/home/peter/php5-5.4.20/ext/readline -DPHP_ATOM_INC -I/home/peter/php5-5.4.20/ext/readline/include -I/home/peter/php5-5.4.20/ext/readline/main -I/home/peter/php5-5.4.20/ext/readline -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /home/peter/php5-5.4.20/ext/readline/readline_cli.c -o readline_cli.lo 
libtool: compile:  cc -I. -I/home/peter/php5-5.4.20/ext/readline -DPHP_ATOM_INC -I/home/peter/php5-5.4.20/ext/readline/include -I/home/peter/php5-5.4.20/ext/readline/main -I/home/peter/php5-5.4.20/ext/readline -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/peter/php5-5.4.20/ext/readline/readline_cli.c  -fPIC -DPIC -o .libs/readline_cli.o
/home/peter/php5-5.4.20/ext/readline/readline_cli.c:54:31: fatal error: readline/readline.h: No such file or directory
compilation terminated.
make: *** [readline_cli.lo] Error 1

As you can see it terminates with a fatal error complaining that it can't find readline.h. any idea what i am doing wrong? could it just be that it will not work on debian wheezy (7)? the dotdeb page instructions only talk about debian squeeze (6)...

share|improve this question
add comment

3 Answers

There is a new package on debian: php5-readline

Just install it (maybe install libreadline-dev before) and you will have the php > promt.

share|improve this answer
1  
i do sudo apt-get install php5-readline and i get E: Unable to locate package php5-readline. do you know which repo the package is in? –  mulllhausen Mar 2 at 21:46
    
Look likes it's in Debian Sid: packages.debian.org/… and I get it from Ubuntu Saucy (Mint). –  Damien Mar 3 at 11:11
    
hmm sid scares me. i changed my sources to sid, did an apt-get update and checked to see what installing the php5-readline package would do, but it looks like sid will change about 160 other packages - things like python and perl which i need. i'll try just leaving it at wheezy and downloading and installing the single package by itself. –  mulllhausen Mar 7 at 22:22
    
unfortunately, sudo dpkg -i php5-readline_5.5.9+dfsg-1_i386.deb has dependency problems. i'm not willing to update to sid, but that would probably allow me to install the package (while breaking lots of other things). for now i'll stick with phpsh which does what i want. maybe they'll add readline to a stable debian release in future. +1 anyway :p –  mulllhausen Mar 7 at 22:32
add comment

I gave up trying on the dotdeb php-cli with readline support for debian wheezy. who would have thought it would be so hard to get php running with an interactive shell in cli mode!? If anyone figures this out, I'd still like to know how you did it, so please post an answer here...

However an alternative equivalent solution is facebook's phpsh. this is an interactive php shell and it has some nice features such as tabtab completion for function names and syntax highlighting for notices.

I installed it like so:

$ sudo apt-get install python # this is necessary to run phpsh
$ cd ~/

$ wget https://github.com/facebook/phpsh/zipball/master
$ unzip phpsh-master.zip

$ cd phpsh-master
$ sudo cp -r src /etc/phpsh # phpsh seems to complain unless it resides at /etc/phpsh
$ sudo ln -s /etc/phpsh/phpsh /usr/bin/phpsh # put phpsh on the $PATH

and voila its ready to use from any dir:

$ cd /etc/apt # some random dir

$ phpsh
Starting php
type 'h' or 'help' to see instructions & features
php> echo 'hi';
hi
php>
share|improve this answer
add comment

Are you sure have installed the following packages? re2c and libreadline-dev

So you need to add a symbolic link inside ext/readline directory to sapi directory ln -s ../../sapi

Then try to compile readline again.

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.