ubuntu系統存在兩個PHP版本,預設版本的坑壞人

helong3314發表於2021-08-12

執行 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 協議》,轉載必須註明作者和本文連結

相關文章