How do you launch the PHP interactive shell?

PHP: How do you launch the PHP interactive shell?

As of PHP 5.1.0, the CLI SAPI provides an interactive shell. To use it, enter the following command at a command line:

  1. php -a

If you run 'php -a' and just see 'Interactive mode enabled', but nothing happens when you type something and hit enter then this means that the interactive shell isn't activated for your installation of PHP. You must have the readline module installed (check if you do by running php -m | grep -i readline).

If you see 'Interactive mode enabled', then after typing in your PHP code (don't forget the opening PHP tag), press ctrl+d

$ php -a
Interactive mode enabled

<?php echo "hello, world" . rand(); ?>

hello, world665146942

Note: in the above output, I hit ctrl+d in the 2nd to last line, then it executed the PHP code that I typed and echoed the output.

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How do you launch the PHP interactive shell?

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the PHP language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to block multiple IP addresses in .htaccess

How to set the Expires header in .htaccess

How do you run a PHP script from the command line?

What is the difference between reference and primitive data types types in Javascript?

How to set up custom error pages in .htaccess for your Apache server (ErrorDocument)

What does PEAR stand for?

301 Redirect a single URL in .htaccess to a new location

How to destroy or remove a cookie in PHP

How to select all rows for a certain month (or day, year or time), using Eloquent

How to check if a user is logged in, inside a blade file?