在 debian wheezy 上安装带有 readline 支持的 php5

在 debian wheezy 上安装带有 readline 支持的 php5

php5-cli 在 debian wheezy 上不提供 readline 支持。这意味着交互式 php shell(以 身份运行$ php -a)没有提示符(php >),而是只说Interactive mode enabled然后将光标留在空白行上。我可以执行 php 但这很尴尬,例如<? echo 'hi'; ?> enterctrld它会执行一个 php 命令,但这绝对不如具有 readline 支持的提示符那么好。

我找到了一些说明要通过 dotdeb 存储库安装带有 readline 支持的 php5-cli,但是我进行了一半,它给出了一个错误:

下载 GPG 密钥

$ 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]

安装 GPG 密钥

$ 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

远程升级

$ 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.

以交互模式测试 PHP

$ php -a
Interactive mode enabled

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

尝试编译 readline 支持

$ 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

运行 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

配置

$ 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

制作

$ 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

正如您所看到的,它以致命错误终止,抱怨找不到readline.h.知道我做错了什么吗?难道它不能在 debian wheezy (7) 上运行吗?点德布页面说明仅谈论Debian 挤压 (6)...

答案1

debian 上有一个新包:php5-readline

只需安装它(也许安装libreadline-dev之前),您将收到php >提示。

答案2

我放弃了尝试使用 dotdeb php-cli 来支持 debian wheezy 的 readline 。谁会想到在 cli 模式下使用交互式 shell 运行 php 会如此困难!?如果有人解决了这个问题,我仍然想知道你是如何做到的,所以请在这里发布答案......

然而,另一种等效解决方案是 facebook 的phpsh.这是一个交互式 php shell,它有一些不错的功能,例如tabtab函数名称的完成和通知的语法突出显示。

我是这样安装的:

$ 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

瞧,它可以从任何目录使用:

$ cd /etc/apt # some random dir

$ phpsh
Starting php
type 'h' or 'help' to see instructions & features
php> echo 'hi';
hi
php>

答案3

您确定已经安装了以下软件包吗? re2c 和 libreadline-dev

所以你需要在 ext/readline 目录中添加一个符号链接到 sapi 目录 ln -s ../../sapi

然后再次尝试编译readline。

答案4

使用点德布。这就像1分钟的工作。

跟随https://www.dotdeb.org/instructions/

只做第1,3,4点(省略2)

进而

sudo apt-get install php5-readline

相关内容