Tuesday, April 26, 2011

How to run a php file in terminal

You can also create php scripts designed to run in the terminal like so:

# php -f php-file.php



1) Fire up a text editor and create your file, eg:

#!/usr/bin/php
// ^^ that line tells the command line that the file should be parsed by the php CLI interpreter
echo "Hello terminal\n";  


2) Give the script execute permissions:

# chmod +x script.php


3) Execute your script:

# ./script.php
Hello terminal



This is all assuming you have the CLI version of PHP. FC installs this by default.



Reference:                                                                                                      
  1. http://www.linuxquestions.org/questions/linux-software-2/can-i-run-php-trom-terminal-435783/

1 comment: