PHP can be used to run command line programs and is not restricted to browser only app development. PHP SH can be installed on Linux, windows and mac which helps you execute php files from your terminal. These programs can fetch data from web server, manipulate the data and store it on hard-disk. Though php can be used for doing command line operations, you can’t execute html specific code from the command line using Php SH. In such case, using php on browser with web server should be your focus like most of the web based programming languages.
You can download phpsh from official github page. It was developed by facebook and they have it updated on their github page. There is a zip and tarball that you can download on your computer. In case of the windows, you have to show the path of the php sh as global variables so that it can properly execute the phpsh on command line.
Most of the linux distros have command like php “php cli” in their repository. e.g. for debian based linux distros you can use the following command to install php cli.
sudo apt-get install php5-cli
You can download that instead of php sh if you want. You’ll be able to execute the php command either way.
Macintosh also has php sh so you can execute php sh and compile php scritps.
Once you install the php sh properly, you can execute the php file from command line (terminal).
As you can see I have my php file where I am printing “hello world” and there is a new line escape character as well. When you execute this code you’ll notice that it shows properly on the terminal.
If you add any HTML tag in your code then It will not render the HTML and instead print those tags as it is. You can see that in the image below.
In order to access the help documentation you can type ‘h’ or ‘help’ on terminal and It will show the documentation.
Have any questions or have any suggestions for me to improve? Feel free to let me know about it in comments. Also you can send me direct message on my twitter handle @maheshkale. 🙂