How to: Run php in interactive mode directly in console window terminal on Linux

To run PHP directly in the console window terminal (in linux), run the following:

php -a

This will enable you to run php in interactive mode. Try the following:

echo 'Hello World';

You should see "Hello World" printed to the terminal. To exit PHP interactive mode, try the following:

exit();

followed by CTRL+C or CMD+C  for mac.

 

You can also run php in non-interactive mode by running:

php path/to/file.php

The file should be a normal php file with starting <?php tags.

One thought on “How to: Run php in interactive mode directly in console window terminal on Linux

Leave a Reply

Your email address will not be published. Required fields are marked *