Ubuntu – Run PHP script from command line

command linePHP

How can I simply run a PHP script in the command line? Also is it possible to run it like it would be if the URL was typed in?

Best Answer

As long as you have php installed, you run a PHP file using

/usr/bin/php /path/to/php/file.php

Or if your $PATH is set up properly to include /usr/bin, then simply

php /path/to/php/file.php

You can check if PHP is installed, by running

which php