1

When trying to run a PHP script from inside Terminal, the script is just echoed to stdout. This happens if the script is executed directly (first line #!/usr/bin/php) called as an argument (/usr/bin/php ./test.php), or if the php command(s) is input interactively.

What could be the problem?

Computer is El Capitan Server, 10.11.6; and, no extra MAMP/Apache/PHP has been installed. On a non-server El Capitan machine, things work as expected; so, I'm stumped...

Adding output of ls command:

sh-3.2# ls -lFa /usr/bin/php
-rwxr-xr-x  1 root  wheel  10577264 Jul  9 11:51 /usr/bin/php*
sh-3.2# 

Adding more output:

sh-3.2# ls -lFa /var/root/test.php
-rwxr-xr-x  1 root  wheel  17 Nov 21 16:48 /var/root/test.php*
sh-3.2# cat /var/root/test.php
<?
phpinfo();
?>
sh-3.2# /usr/bin/php /var/root/test.php
<?
phpinfo();
?>
sh-3.2# od -c /var/root/test.php
0000000    <   ?  \n   p   h   p   i   n   f   o   (   )   ;  \n   ?   >
0000020   \n                                                            
0000021
sh-3.2# od -x /var/root/test.php
0000000      3f3c    700a    7068    6e69    6f66    2928    0a3b    3e3f
0000020      000a                                                        
0000021
sh-3.2# 
  • What is output from the command ls -l /usr/bin/php? – Graham Miln Nov 21 '16 at 8:14
  • @GrahamMiln - Updated the question. – Kent Nov 21 '16 at 8:25
  • Thank you. Could the script contain non-ASCII characters or be UTF8+BOM formatted? If so, try stripping these as that could confuse the shell. Unlikely but worth a try. Also does, /usr/bin/php <absolute path to test.php> work? – Graham Miln Nov 21 '16 at 10:24
  • Added more info, @GrahamMiln . I also considered the UTF8 problem, because the original script I was running did have some Japanese comments. But, as you can see, that's not an issue with the test script. Running as root, to rule out permissions issues as well... – Kent Nov 21 '16 at 22:52
  • Use "<?php\nphpinfo();" instead of your test.php content. "\n" means new line (which I can't express in the comment here). – klanomath Nov 21 '16 at 23:18
1

Use the long tag like

<?php
phpinfo();

in test.php instead of your somehow malformed test.php and it should work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .