After successful installation of PHP on the web servers, many people confuse how to execute PHP script from command line.
If you follow auto installation procedure such as yum or apt, then PHP CLI feature should be installed by default. If PHP installation done from
compiling source, then there is little steps to follow to get PHP CLI to work .
1) Find PHP bin file
First you should try to find PHP bin and make sure it exist
1 |
find / -name php -type f |
If PHP binary does exist, you will find path to binary file
1 |
/path/to/your/php/bin/php |
If PHP binary does not exist, you may need to recompile PHP
2) Add PHP to bash profile
If PHP exists on your system, add the path to bash_profile
1 |
vim ~/.bash_profile |
then replace the actual path of the PHP bin
1 2 3 |
PATH=$PATH:/path/to/your/php/bin/ .... export PATH |
3) save and reload the file
This is to ensure your current session has access to new path changes. otherwise you need to open fresh terminal windows.
1 |
#source ~/.bash_profile |
4) Verify
1 2 3 4 5 |
# php -v PHP 5.4.38 (cli) (built: Oct 9 2015 09:09:42) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.5, Copyright (c) 1999-2015, by Zend Technologies |
now you should be able to run PHP script from cli