PHP Useful CLI Commands List

PHP Useful CLI Commands List

PHP Version : To verify your default PHP version.

$ php -v

PHP Info : We can use phpinfo() which is a very valuable debugging tool directly on the Linux command-line without the need of calling it from a file, simply as :

$ php -r 'phpinfo();'

Set Default PHP7.2 Version : To set php default version use below command.

$ sudo update-alternatives --set php /usr/bin/php7.2

Enable/Disable PHP Version : To enable new php version first disable the active php version using a2dismod command and then enable the one you want to enable by using a2enmod command.

$ sudo a2dismod php7.1

$ sudo a2enmod php7.2

$ sudo systemctl restart apache2 or $ sudo service apache2 restart

Check Installed Version : To see the php installed version use below command. It lists down the all installed versions.

sudo update-alternatives --list php

Find PHP installed path : To see the the installed php version path use below command.

which php

PHP Interactive Mode : Run PHP in Interactive mode and do some mathematics. Simply as :

php -a

You can create function also.

php -a

php > function addition ($a, $b)

php > {

php { echo $a + $b;

php {}

php > var_dump (addition(4,3));


Press exit or ctrl+c to close PHP interactive mode.

Tagged , ,