事情经过是这样的,在ubuntu系统下要用EleasticSearch – PHP 插件,然后用composer安装结果出现和PHP版本不符合的报错。
执行 PHP -v
vagrant@ubuntu-14:/usr/bin$ PHP -v
PHP 5.5.9-1ubuntu4.21 (cli) (built: Feb 9 2017 20:54:58)
copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, copyright (c) 1999-2014, by Zend Technologies
执行 whereis PHP
vagrant@ubuntu-14:/usr/bin$ whereis PHP
PHP: /usr/bin/PHP /usr/bin/X11/PHP /usr/local/PHP /usr/share/PHP /usr/share/man/man1/PHP.1.gz
查看,果然有两个PHP版本,/usr/bin/PHP , /usr/local/PHP,为保证只运行PHP7断然决定卸载一个。
卸载PHP
sudo apt-get autoremove PHP5-common
执行 whereis PHP
vagrant@ubuntu-14:/etc/PHP5$ whereis PHP
PHP: /usr/local/PHP /usr/share/PHP
执行 PHP -v
vagrant@ubuntu-14:/etc/PHP5$ PHP -v
The program 'PHP' is currently not installed. You can install it by typing:
sudo apt-get install PHP5-cli
到此,基本把PHP5给卸载掉了,然后尝试执行 composer
sudo composer install
/usr/bin/env: PHP: No such file or directory
什么鬼还找到不那个文件或者目录。
解决办法:这个问题应该是找不到PHP的执行文件,env会通过$PATH所指定的路径去寻找PHP的可执行文件。
执行:vim /etc/environment,在PATH最后添加 :/usr/local/PHP/bin/PHP,退出保存后,切换到root下执行 source /etc/environment
执行:$PATH,查看一下是否添加成功。
执行:PHP -v
PHP -v
PHP 7.0.7 (cli) (built: May 3 2017 17:31:36) ( NTS )
copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, copyright (c) 1999-2016, by Zend Technologies
可以看到cli已经是PHP7.0.7啦,到这是不是很开心啦。
执行:composer
sudo composer install
/usr/bin/env: PHP: No such file or directory
尼玛,什么鬼怎么还报错,不要着急,接着往下操作。
这是因为我们环境变量的执行文件在/usr/local/bin目录下,而我们的实际执行文件在/usr/local/PHP/bin/PHP 下,所以建一个软连接
ln -s /usr/local/PHP/bin/PHP /usr/local/bin/PHP
这样问题就愉快地解决啦。
再次执行composer,稍等片刻,安装成功。
sudo composer install
Loading composer repositories with package @R_605_4045@ion
Updating dependencies (including require-dev)
Package operations: 5 installs, 0 updates, 0 removals
- Installing react/promise (v2.5.1): Downloading (100%)
- Installing guzzlehttp/streams (3.0.0): Downloading (100%)
- Installing guzzlehttp/ringPHP (1.1.0): Downloading (100%)
- Installing psr/log (1.0.2): Downloading (100%)
- Installing elasticsearch/elasticsearch (v5.3.0): Downloading (100%)
elasticsearch/elasticsearch suggests installing monolog/monolog (Allows for client-level logging and tracing)
Writing lock file
Generating autoload files