Probably, many were faced with the issue of a broken interactive PHP console.
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 commands entered does not work. In fact this is not true. In fact, this is a special mode, which must also be able to use. The job description of this mode is not included in the tasks of my post. For the ordinary uninitiated user, he looks like this: nothing works. But in order to "work" the way we used to in the python or node.js consoles, we will do it.
After some googling, most links give advice to recompile PHP with support for the readline library. That she, they say, is responsible for the work of PHP in an interactive mode. Yes, exactly: in your PHP build, readline does not work. Moreover, in Debian Linux you will not be able to install this out-of-the-box support due to problems with the licensed nature of the distributor. There is no
php5-readline package in it. However, there is a simpler and “legal” way to make the PHP console work, rather than rebuilding the entire PHP and its “manual” installation, after which your PHP drops out of the standard operating system update mechanism, and in the case of a subsequent random PHP installation from package is fraught with conflicts.
')
At once I will make a reservation that everything said relates 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 it myself, but I saw the
php5-readline package in the corresponding repository and saw the
fixed conclusion in the corresponding bug report topics. That is, as I understand it, in Debian Jessie and PHP 5.5, this support will be out of the box.
Back to Wheezy and PHP 5.4 ...
Written with some minor modifications is quite applicable to other Linux distributions, the principle is the same.
We do everything from under the root or precede it with the
sudo command .
1. First we need the 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 PHP source. Take them from the OS repository
# apt-get source php5-cli
3. We will not rebuild all PHP. we only need one module. Him and collect
# cd php5-5.4.4 / ext / readline /
# phpize
# ./configure
# make
4. Here we will have an underwater stone: when compiling, the compiler will not find sapi.h
# ln -s ../../sapi/
# make
5. Build completed successfully. We take the new module
readline.so , put it to the modules of the current PHP and rule configs
Module:
# locate mcrypt.so | grep php
# cp modules / readline.so / usr / lib / php5 / 20100525 + lfs /
# chmod -x /usr/lib/php5/20100525+lfs/readline.so
Here, the
locate command is used to determine the path where the PHP layouts are based on the example of mcrypt, which is installed automatically when you install PHP. If you do not have a
locate command, determine your path by analogy with my
Config:
# echo 'extension = readline.so'> /etc/php5/mods-available/readline.ini
# cd /etc/php5/cli/conf.d
# ln -s ../mods-available/readline.ini 20-readline.ini
Everything. The console works.
# php -a
Interactive mode enabled
php>