
php5-cli bietet keine Readline-Unterstützung unter Debian Wheezy. Dies bedeutet, dass die interaktive PHP-Shell (ausgeführt als $ php -a
) keine Eingabeaufforderung ( php >
) hat, sondern nur anzeigt Interactive mode enabled
und den Cursor dann auf einer leeren Zeile belässt. Ich kann PHP ausführen, aber es ist umständlich, z. B. <? echo 'hi'; ?>
enterctrldwird ein PHP-Befehl ausgeführt, aber das ist bei weitem nicht so schön wie die Eingabeaufforderung mit Readline-Unterstützung.
Ich habe einige Anweisungen gefundenum php5-cli mit Readline-Unterstützung über das Dotdeb-Repository zu installieren, komme ich jedoch auf halbem Weg an und es tritt ein Fehler auf:
GPG-Schlüssel herunterladen
$ 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-Schlüssel installieren
$ 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.
Testen Sie PHP im interaktiven Modus
$ php -a
Interactive mode enabled
<?php echo 'hi'; ?>
hi$ # this is not what i want!
Versuchen Sie, Readline-Unterstützung zu kompilieren
$ 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
Führen Sie phpize aus
$ 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
Konfigurieren
$ 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
Machen
$ 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
Wie Sie sehen, wird es mit einem schwerwiegenden Fehler beendet, der besagt, dass es nicht gefunden werden kann readline.h
. Irgendeine Idee, was ich falsch mache? Könnte es einfach sein, dass es unter Debian Wheezy (7) nicht funktioniert? Die Dotdeb-SeiteAnweisungen sprechen nur vondebian-squeeze (6) …
Antwort1
Es gibt ein neues Paket für Debian:php5-readline
Installieren Sie es einfach (vielleicht installierenlibreadline-devvorher) und Sie erhalten die php >
Eingabeaufforderung.
Antwort2
Ich habe es aufgegeben, es mit der dotdeb-php-cli mit Readline-Unterstützung für Debian Wheezy zu versuchen. Wer hätte gedacht, dass es so schwierig ist, PHP mit einer interaktiven Shell im CLI-Modus zum Laufen zu bringen!? Wenn das jemand herausfindet, würde ich trotzdem gerne wissen, wie Sie es gemacht haben, also posten Sie bitte hier eine Antwort ...
Eine gleichwertige Alternative bietet jedoch Facebook phpsh
. Dabei handelt es sich um eine interaktive PHP-Shell mit einigen netten Features, wie etwa tabtabder Vervollständigung von Funktionsnamen und der Syntaxhervorhebung von Hinweisen.
Ich habe es so installiert:
$ 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
und voilà, es ist von jedem Verzeichnis aus einsatzbereit:
$ cd /etc/apt # some random dir
$ phpsh
Starting php
type 'h' or 'help' to see instructions & features
php> echo 'hi';
hi
php>
Antwort3
Sind Sie sicher, dass Sie die folgenden Pakete installiert haben? re2c und libreadline-dev
Sie müssen also einen symbolischen Link im Verzeichnis ext/readline zum Verzeichnis sapi hinzufügen ln -s ../../sapi
Versuchen Sie dann, Readline erneut zu kompilieren.
Antwort4
Verwenden Sie dotdeb. Das dauert ungefähr 1 Minute.
Folgenhttps://www.dotdeb.org/instructions/
Führen Sie nur die Punkte 1,3,4 aus (lassen Sie 2 weg)
und dann
sudo apt-get install php5-readline