進捗どうでしょう

主な話題は 社会人生活/情報工学/アニメ/ライトノベル/漫画/映画/自炊 などです。

MENU

PHPのバージョン違いによるcomposer updateエラー

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- laravel/framework v7.10.3 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
- laravel/framework v7.9.2 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
- laravel/framework v7.9.1 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
- laravel/framework v7.9.0 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
- laravel/framework v7.8.1 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
- laravel/framework v7.8.0 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
- laravel/framework v7.7.1 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
- laravel/framework v7.7.0 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
- laravel/framework v7.6.2 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
- laravel/framework v7.6.1 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.

 composerをupdateしようとしたところ上のようなエラーが出ました。エラー文を読めばPHPのバージョンが違うことが原因だとわかります(laravelの要求はPHPv7.2.5、環境にあるのはPHPv7.1.33)。したがってPHPのバージョン7.1.33をアンインストールして7.2.5をインストールすればいいとわかるのですが結構詰まったのでメモ。

 まず、現在のPHPを確認。

 $ php -v
PHP 7.1.33 (cli) (built: Oct 31 2019 17:36:04) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

  案の定v7.1.33ですね。

 そこでとりあえず現在入っているPHPを全てアンインストールしようとすると下のように言われました。

$ sudo yum remove php php-*
Loaded plugins: priorities, update-motd, upgrade-helper
No Match for argument: php
No Match for argument: php-*
No Packages marked for removal 

 php-*なんてどこにもないって言われてますね。

 原因は単純で、phpのファイル名はphp-71ではなくてphp71です。

 yum removeではphp-*ではなくphp*と指定しましょう(ネットでPHPの削除方法をググると何故か皆コピペしたように上のコマンドを紹介するので引っ掛かりました)。

  以下のようにするとうまくいきます。

$ sudo yum remove php*
Loaded plugins: priorities, update-motd, upgrade-helper
Resolving Dependencies
--> Running transaction check
---> Package php71.x86_64 0:7.1.33-1.43.amzn1 will be erased
---> Package php71-cli.x86_64 0:7.1.33-1.43.amzn1 will be erased
---> Package php71-common.x86_64 0:7.1.33-1.43.amzn1 will be erased
---> Package php71-fpm.x86_64 0:7.1.33-1.43.amzn1 will be erased
---> Package php71-json.x86_64 0:7.1.33-1.43.amzn1 will be erased
---> Package php71-mbstring.x86_64 0:7.1.33-1.43.amzn1 will be erased
---> Package php71-mysqlnd.x86_64 0:7.1.33-1.43.amzn1 will be erased
---> Package php71-pdo.x86_64 0:7.1.33-1.43.amzn1 will be erased
---> Package php71-process.x86_64 0:7.1.33-1.43.amzn1 will be erased
---> Package php71-xml.x86_64 0:7.1.33-1.43.amzn1 will be erased 

  これでPHP v7.1系をアンインストールできたはずなので、あとはPHP v7.2系をインストールするだけです。

 バカなミスでした。