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 convert a string to an array of it's characters in PHP?

How do you access the php://input stream?

How to find an item by Primary Key in Eloquent, or throw a ModelNotFoundException exception if it isn't found?

How to set the Expires header in .htaccess

What are the main error types in PHP

How to set up an alias to map one directory to another destination

How to enable the rewrite engine in .htaccess?

Force trailing slash (redirect if no trailing slash exists) in .htaccess

How to install and use optipng on Linux CentOS

How to find the intersection (same values) from two arrays?