If you want to run php script in shell, simply put the following line at the beginning of your php file.

#!/path/to/php

#!/path/to/php is the path you installed php in linux. If you don’t know where php is installed in your linux. Type the following command

which php

This will output the php path from your linux. The output will be something like this

/usr/bin/php

For example: hello.php

#!/usr/bin/php
<?php
echo “Hello World!”;
?>

Make your php script executable by typing

chmod +x hello.php

And then run it

./hello.php

You’ll see

Hello World!