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 see all of the options for an artisan command?

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

How to access the Laravel's route parameters outside of the controller?

How to get the last character of a string in JS?

How to add comments in PHP

How to split a string into an array, in JS

Why should you update APP_URL from from http://localhost?

What is Bubble sort, and how to write an implementation of it in PHP

How to have a whitelist of IP addresses that can access files in .htaccess

How to check if a relation was loaded on an Eloquent model already?