ubuntu系统存在两个PHP版本,默认版本的坑坏人

执行 php -v

PHP 7.2.24-0ubuntu0.18.04.8 (cli) (built: Jul  5 2021 17:41:32) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24-0ubuntu0.18.04.8, Copyright (c) 1999-2018, by Zend Technologies

 whereis php
 php: /usr/bin/php /usr/bin/php7.2 /usr/lib/php /etc/php /usr/include/php /usr/local/php /usr/share/php7.2-xml /usr/share/php /usr/share/php7.2-common /usr/share/php7.2-json /usr/share/
php7.2-opcache /usr/share/php7.2-readline /usr/share/man/man1/php.1.gz

查看,果然有两个php版本,/usr/bin/php , /usr/local/php,为保证只运行php7.4,断然决定卸载php7.2。

apt-get autoremove php7.2-common

DESKTOP-BHVUG0D# sudo apt-get autoremove php7.2-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  debhelper dh-autoreconf dh-strip-nondeterminism libarchive-cpio-perl libarchive-zip-perl libfile-stripnondeterminism-perl libsodium23 libtimedate-perl
  php-common php-dev php-pear php-xml php7.2-cli php7.2-common php7.2-dev php7.2-json php7.2-opcache php7.2-readline php7.2-xml pkg-php-tools shtool
0 upgraded, 0 newly installed, 21 to remove and 155 not upgraded.
After this operation, 23.7 MB disk space will be freed.

卸载完成查看

 whereis php
 php: /usr/lib/php /etc/php /usr/include/php /usr/local/php /usr/share/php
php -v
zsh: command not found: php

到此,基本把php5给卸载掉了,然后尝试执行 composer

/usr/bin/env: ‘php’: No such file or directory

由于把之前默认的版本删除掉,找不到PHP版本,加软连接

ln -s /usr/local/php/bin/php /usr/local/bin/php
 php -v

PHP 7.4.12 (cli) (built: May 20 2021 23:38:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

到此就设置成功了

本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 2
xiaochong0302

你也可把默认的设置成7.4呀

3年前 评论

@xiaochong0302 composer 的时候默认成低版本的, 而项目运行的时候是高版本的,所以才直接卸载的

3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!