3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

composer install のエラー as the wrong version (~~~) installed. の解決

Posted at

まとめ

  • composer installは.lockがあるときはそっちを参照する
  • php extensionはphpに勝手に入っているライブラリで、phpのバージョンアップで更新できる

環境
php: 7.1.19


composer install すると

Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested PHP extension ext-simplexml ^7.2 has the wrong version (7.1.19) installed. Install or enable PHP's simplexml extension.
  Problem 2
    - The requested PHP extension ext-json ^1.6 has the wrong version (1.5.0) installed. Install or enable PHP's json extension.
  Problem 3
    - The requested PHP extension ext-zip ^1.15 has the wrong version (1.13.5) installed. Install or enable PHP's zip extension.

こんなエラーが出てくる。

composer installとは

そもそもcomposer installは何をしているのかを調べた。

composer install は公式ドキュメントをみて解釈すると

composer.jsonを参照し依存関係を解決しながらvendorディレクトリにパッケージを追加するコマンド。
composer.lockがある場合はそちらを使用する。

つまりlockファイルがあるときはそっちを参照してしまう。

一旦の対処法

composer.lockを覗くと

    "platform": {
        "php": "^7.1.3",
        "ext-simplexml": "^7.2",
        "ext-json": "^1.6",
        "ext-zip": "^1.15"
    },

と書かれている。下三つの記述をエラーメッセージのversionまで下げたらcomposer installできた。
しかしext-simplexml等は今からvendorファイルにインストールするはずなのに、なんでversionが古いと怒られるのか?

グローバルでインストールされているのかと思い、調査した。

php extentionとは

php extentionとは、phpそれぞれのversionでインストールされているライブラリのこと。勝手にインストールされているものもあればされていないものもある。

php -i | grep json

json version => 1.5.0

確かに自分のphpの設定でext-jsonがversion1.5.0であることが確認できた。
このversionは個別にアップデートするものではなく、phpのバージョンアップに追随して更新されるみたい。

なのでphpのアップデートをしなければならないことがわかった。

php 7.2.22へ

アップデートしないといけないことがわかったので、phpを7.2.22へ、phpbrew使いました。
インストールに16分かかったんだが、何これ

まあ無事インストールできたのでもっかいcomposer install
...できた、、、、疲れた

phpbrew 使うとextensionのversion簡単に確認できる

余談ですが、phpbrew使うとコマンドで簡単にextensionのversionを確認することができました。

$phpbrew extension

Loaded extensions:
 [*] bcmath       7.2.22      
 [*] bz2          7.2.22      
 [*] calendar     7.2.22      
 [*] ctype        7.2.22      
 [*] curl         7.2.22      
 [*] date         7.2.22      
 [*] dom          20031129    
 [*] fileinfo     1.0.5       
 [*] filter       7.2.22      
 [*] gd           7.2.22      
 [*] hash         1.0         
 [*] iconv        7.2.22      
 [*] json         1.6.0     

こんな感じ、extensionの導入も phpbrewコマンド経由で可能、かなり便利だと感じた。

以上

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?