Page 1 of 1

How we run PHP program in terminal?

Posted: Tue Feb 26, 2019 11:03 am
by rajan
I'm starting learning PHP but don't know how to run in terminal. On localhost successfully I can run.

Re: How we run PHP program in terminal?

Posted: Wed Feb 27, 2019 2:02 am
by Emohlyni
Starting from version 4.3, PHP supports the new SAPI type (Server Application Programming Interface) called CLI, which means Command Line Interface. As the name implies, the main task of this SAPI-type is to develop shell / shell (or desktop) applications using PHP. There are very small differences between the CLI SAPI and other SAPIs, which will be further discussed in this chapter.

The CLI SAPI was released for the first time with PHP 4.2.0, but then it was an experiment, and you had to explicitly turn it on with the --enable-cli command when starting ./configure. Beginning with PHP 4.3.0, the CLI SAPI is no longer experimental and is always embedded and installed as a binary php executable (called php.exe in Windows).

Significant differences of CLI SAPI from other SAPI:

Unlike CGI SAPI, no headers are written to the output.

Although CGI SAPI has a way to suppress HTTP headers, there is no equivalent switch for including them in CLI SAPI.

There are certain php.ini directives that are redefined in the SAPI CLI because they have no meaning in the shell environment.

Re: How we run PHP program in terminal?

Posted: Wed Feb 27, 2019 1:40 pm
by mehargags
in short

in your SSH Terminal run any PHP script using
/usr/bin/php <path-to-script-name.php>