Can not use command line interpreter

前端 未结 9 1010
盖世英雄少女心
盖世英雄少女心 2021-02-05 09:58

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 ena

相关标签:
9条回答
  • 2021-02-05 10:29

    If you're using Mac, then install Homebrew (http://brew.sh) then type: brew install phpsh

    And then you can run phpsh to get an interactive shell.

    0 讨论(0)
  • 2021-02-05 10:32

    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.

    0 讨论(0)
  • 2021-02-05 10:33

    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
    #
    
    0 讨论(0)
  • 2021-02-05 10:34

    Install this:

    php5-readline
    

    then try use:

    php -a
    
    0 讨论(0)
  • 2021-02-05 10:34

    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
    
    0 讨论(0)
  • 2021-02-05 10:34

    Because module readline not installed. http://php.net/manual/en/features.commandline.interactive.php

    This is how I install the module by recompiling php source codes:

    Find previous Configure command:

    $ php -i | grep configure
    Configure Command =>  './configure'  '--prefix=/usr/local/php7' ...
    

    Then recompile:

    ./configure --prefix=/usr/local/php7 \
    --with-readline \
    
    ...
    
    $ make clean 
    $ make
    $ make test 
    $ sudo make install
    

    Check if readline module installed:

    $ php m | grep readline
    readline
    

    Then start php Interactive shell:

    $ php -a
    Interactive shell
    
    php >
    
    0 讨论(0)
提交回复
热议问题