Support for the PHP interactive console under Debian Linux

Probably, many came across the issue of a broken interactive console PHP.

When you enter
# php -a

and you see only the inscription “Interactive mode enabled”, after which whatever you enter, the interpretation and execution of the entered commands does not work. In fact this is not true. In fact, this is a special mode, which must still be able to use. The description of the operation of this mode is not included in the tasks of my post. For an ordinary uninitiated user, it looks like this: nothing works. But in order to “work” the way we are used to in the python or node.js consoles, we will do it.

After some googling, most links give advice to recompile PHP with readline library support. It is she who is supposedly responsible for the work of PHP in interactive mode. Yes, exactly so: readline does not work in your PHP assembly. Moreover, in Debian Linux, you will not be able to install this support out of the box due to licensing problems of the distributor. There is simply no php5-readline package in it. Nevertheless, there is a simpler and “legal” way to make the PHP-shnu console work, rather than rebuilding all of PHP and its “manual” installation, after which your PHP falls out of the standard mechanism for updating the operating system, and in case of subsequent accidental installation of PHP from the package is fraught with conflicts.

Immediately make a reservation that all of the above applies to the current stable version of Debian Wheezy. In the next, unstable version of Debian, this support seems to be returned. Unfortunately, I did not check this myself, but I saw the php5-readline package in the corresponding repository and saw the fixed conclusions in the corresponding topics of bug reports. That is, as I understand it, in Debian Jessie and PHP 5.5, this support will be out of the box.

Let's go back to Wheezy and PHP 5.4 ...
Written with some small modifications is quite applicable to other Linux distributions, the principle is the same.

We do everything from under the root or precede the sudo command .

1. First of all we need dev packages for PHP and readline
# aptitude install php5-dev libedit-dev libreadline-dev

Packages php, libedit, libreadline if not installed before, will be installed automatically.

2. Next, we need the source code for PHP. We take them from the OS repository
# apt-get source php5-cli

3. We will not rebuild all PHP. we need only one module. And collect it
# cd php5-5.4.4 / ext / readline /
# phpize
# ./configure
# make

4. A pitfall awaits us here: when compiling, the compiler will not find sapi.h
# ln -s ../../sapi/
# make

5. Build completed successfully. We take the newly-made module , put it to the modules of the current PHP and edit the configs

# locate | grep php
# cp modules / / usr / lib / php5 / 20100525 + lfs /
# chmod -x /usr/lib/php5/20100525+lfs/

Here, the locate command is used to determine the path where the PHP files lie, using the example of mcrypt, which is installed automatically when installing PHP. If you do not have the locate command , define your path by analogy with my

# echo 'extension ='> /etc/php5/mods-available/readline.ini
# cd /etc/php5/cli/conf.d
# ln -s ../mods-available/readline.ini 20- readline.ini

Everything. The console is working.
# php -a
Interactive mode enabled


Also popular now: