shell_exec(php -v)返回不同版本的php -v在终端

时间:2017-10-16 14:38:24

标签: php bash macos shell path

这是我在macOS Sierra上的终端中运行时显示的内容

php -v

PHP 7.0.15 (cli) (built: Feb 13 2017 10:30:54) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.15, Copyright (c) 1999-2017, by Zend Technologies 
    with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans

当我在PHP中使用shell_exec运行命令时,我得到了不同的结果

echo shell_exec("php -v");

PHP 5.6.30 (cli) (built: Feb 7 2017 16:18:37) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

即使我从与shell_exec相同的文件中运行phpversion,我也会得到不同的结果

echo phpversion();

7.0.15

我已经搜索了几个小时试图找出如何告诉shell_exec指向位于

的正确版本的PHP
/usr/local/php5/bin/php

但似乎总是使用位于

的预装版本
/usr/bin/php

我的bash个人资料如下

sudo nano ~/.bash_profile

export PATH=/usr/local/php5/bin:$PATH

任何建议或帮助都会非常感激,因为这个问题让我完全糊涂了。

0 个答案:

没有答案