How can I run a PHP script from the command line using the PHP interpreter which is used to parse web scripts?
I have a phpinfo.php file which is accessed from the web shows that German is installed. However, if I run the phpinfo.php from the command line using – php phpinfo.php and grep for German, I don’t find it. So both PHP files are different. I need to run a script which the php on which German is installed.
How can I do this?
You should check your server configuration files. Look for lines that start with
LoadModule php…There probably are configuration files/directories named
modsor something like that. Start from there.You could also check output from
php -r 'phpinfo();' | grep phpand compare lines tophpinfo();from web server.To run
phpinteractively:(So you can paste/write code in the console.)
To make it parse a file and output to the console:
Parse a file and output to another file:
Do you need something else?
To run only a small part, one line or like, you can use:
If you are running Linux then do
man phpat the console.If you need/want to run PHP through fpm (FastCGI Process Manager), use cli fcgi:
Where /var/run/php-fpm/php-fpm.sock is your php-fpm socket file.