Home / VPS & Dedicated / How to run a PHP script from the command line

How to run a PHP script from the command line

PHP Elephant
Question: I want to troubleshoot a PHP script. How do I run it from the command line?

Answer: In order to successfully run PHP from the command line, you will need to install PHP as CGI. In many Linux distributions, there will be a package in the repository that allows you to install it rather easily. Furthermore, many web hosting providers will setup a server for you in this manner by default.

To run a PHP script from the command line, type:

/path/to/php -f /path/to/script.php

The “-f” flag tells PHP that you want to parse the file. This is very useful if your PHP script is not working but is also not giving you any errors, or any helpful ones. Sometimes you will get more from the command line. This can also be useful if PHP is your scripting language of choice. You can setup automated tasks to run your PHP scripts using Cron.

Photo Source: Flickr

Check Also

Uk data center

Professional Data Centres In The UK

A professional data centre is a location in which various pieces of hardware are located …

Powered by Namesco
© Copyright InternetBlog.Org.Uk 2024, All Rights Reserved