Can not use command line interpreter

2019-03-18 03:19发布

I have tried to execute simple php code in the php interpreter. When I executed the command php -a I getting the message

Interactive mode enabled

Without any place for php input. But I can execute a php code through the command php -r. for example:

php -r "echo 'Hello stackoverflow!';"

Hello stackoverflow!

9条回答
再贱就再见
2楼-- · 2019-03-18 03:35

There seems to be a compilation / linkage error between your PHP and libreadline. This is documented in PHP Bug #48759.

  • Did you compile PHP by yourself? Did you play around with --configure and didn't do a proper make clean before your final build?
  • Does php -m list readline as enabled feature? (Is PHP built with option --with-readline)
  • What is you php version?
  • What distribution do you use?
  • Do you have the libreadline (the *-dev package) installed?
查看更多
ゆ 、 Hurt°
3楼-- · 2019-03-18 03:40

To check if you have readline module installed, type: php -m | grep readline

If nothing displayed, install readline module: sudo apt-get install php5-readline

After module installation you can recheck it's presence with previous command, than enter interactive mode with: php -a

查看更多
一夜七次
4楼-- · 2019-03-18 03:41

After I got tired of compiling it on each machine I used PHPSH (as mentioned by joey-adams)

It is much better then php -a (syntax highlighting and autocompletion)

Install python phpsh

look at install-php5-with-readline-support-on-debian-wheezy

$ 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
查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-03-18 03:42

This is what you should see:

# php -a
Interactive shell

php > echo 1+1;
2
php > echo PHP_VERSION;
5.3.2-1ubuntu4.14
php > exit
#
查看更多
小情绪 Triste *
6楼-- · 2019-03-18 03:46

Install this:

php5-readline

then try use:

php -a
查看更多
Lonely孤独者°
7楼-- · 2019-03-18 03:46

type php -m and make sure you have the readline module. If you don't you won't be able to use it.

http://www.php.net/manual/en/features.commandline.interactive.php

As of PHP 5.1.0, the CLI SAPI provides an interactive shell using the -a option if PHP is compiled with the --with-readline option.

查看更多
登录 后发表回答