ubuntu系统两个PHP版本坑坏人

2022-08-03 14:10:08 浏览数 (1)

事情经过是这样的,在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

竟然显示的是php 5.5.9 ,可明明我安装的是php7 执行 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 information 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

0 人点赞