How to run a PHP script from the command line

posted: Tuesday 10 November 2009 by Tavis J. Hampton in: Web Hosting VPS & Dedicated Web servers

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

1 stelle2 stelle3 stelle4 stelle5 stelle (no votes)
share this 0 comments

Related posts

Server OS Tips del 30 Jul 2010
Server Backup Tips del 30 Jul 2010
Server Hardware Tips del 28 Jul 2010
Server Maintenance Tips del 28 Jul 2010

Be the first to add a comment to this article.

Your email address is required but won't be displayed.
Leave a comment

Register to reserve your nickname accross all the blogs in the Blogo network and to upload your avatar. If you already are registered, login to user your nickname.

Yes No

Comment preview

Network Blogo