0
0

More than 1 year has passed since last update.

開発環境docker編:MacのiTerm2でphpdotenvをインストールすると、PHP Composerのバージョンが古いため完了できない問題の解決

Last updated at Posted at 2023-02-13

背景

Mac、iTerm2、Docker環境で、PHPの環境変数を設定するために、phpdotenvというライブラリをインストールしたところ、以下のメッセージが出て完了できなかった。
PHP Composerをバージョン2にせよとの内容。

全てのメッセージ

//repo.packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/
Info from https://repo.packagist.org: #StandWithUkraine
Using version ^5.5 for vlucas/phpdotenv
./composer.json has been updated
Loading composer repositories with package information
Warning from https://repo.packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies (including require-dev)
Package operations: 6 installs, 0 updates, 0 removals
  - Installing symfony/polyfill-php80 (v1.27.0): Downloading (100%)
  - Installing symfony/polyfill-mbstring (v1.27.0): Downloading (100%)
  - Installing symfony/polyfill-ctype (v1.27.0): Downloading (100%)
  - Installing phpoption/phpoption (1.9.0): Downloading (100%)
  - Installing graham-campbell/result-type (v1.1.0):Downloading (100%)         )
  - Installing vlucas/phpdotenv (v5.5.0): Downloading (100%)
Writing lock file
Generating autoload files
6 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

エラーが起こった場面

Macでdockerを起動し、iTerm2でインストールしたい階層へ移動し、以下のコマンドを入力。

docker-compose exec app composer require vlucas/phpdotenv

何をやっても「command not found」と返される

検索するとあちこちで共通の手法が紹介されていたがうまくいかない。アップデート、削除、インストール共にファイルがないと返される。

解決:全てのコマンドの前にdocker-composeでPHPを呼び出す記述を挿入

学習教材のDockerを見直し、あることに気づく。
これまで調べた情報は全てDocker環境ではないものであり、全てのコマンドの前にdocker-composeでPHPを呼び出す記述が必要では?と思い、実施したところ解決。
道理で何をしても変化がないわけである。以下は直接のアップデートのコマンドだが、その他のコマンドも全て同様であった。

docker-compose exec app composer self-update --2

※最後尾のバージョン指定を端折るとアップデートされなかった。

0
0
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
0
0