1
1

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 3 years have passed since last update.

Docker + Composer + Laravel環境でPHPのバージョンを下げないといけなくなった

Last updated at Posted at 2020-12-14

結論

composer.json
"platform": 
{
    "php": "7.3" #したいversionを入れる 
}

を入れて composer update を実行

FROM php:7.3-fpm-buster

に書き換えてdocker-compose up -d
すればOK

背景

もうすでに動かしていたLaravel環境のPHPを7.4から7.3に変更しないといけなくなった
composerでライブラリを管理しているけど、コンテナイメージを7.3にしただけだと動かない
こんな感じのエラー出る

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - This package requires php ^7.4.0 but your PHP version (7.3.24) does not satisfy that requirement.

詳細

環境

Docker

FROM php:7.4-fpm-buster
//以下略

FROM php:7.3-fpm-buster
//以下略

にして動かしたい

方法

1 composer.json追記

composer.json
"platform": 
{
    "php": "7.3" #したいversionを入れる 
}

を入れて composer update を実行


### 2 dockerイメージを消す

```
docker-compose down --rmi all --volumes
```

をやる

### 3 DockerFile書き換え

```DockerFile
FROM php:7.4-fpm-buster
//以下略
```

を

```DockerFile
FROM php:7.3-fpm-buster
//以下略
```
書き換え

### 4 ビルド

```docker-compose up -d --build``` を実行
そうすると?

```
$ docker-compose exec php bash
$ hoge@fugafugab5318:/var/www/html# php -v
PHP 7.3.24 (cli) (built: Nov 18 2020 10:14:01) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies 
```

以上
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?