0
0

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.

エラー Exception: DateTime::__construct(): Failed to parse time string ~でLaradockの人はコンテナのTZの確認をした方が良い話

Last updated at Posted at 2021-07-05

タイトルがすべてです。
こんなエラーがでた

Exception: DateTime::__construct(): Failed to parse time string (release_start) at position 0 (w): The timezone could not be found in the database

解決策を検索…

参考URL:https://www.out48.com/archives/1849/

修正方法

php.iniの内容を以下に書き換える。

date.timezone = Asia/Tokyo

②**date_default_timezone_set()**関数を事前に呼び出す。

date_default_timezone_set('Asia/Tokyo');

普通の解決方法であれば①だなあとapp内に確認しにいったら、設定はされているがエラーがでていた。
②をやってみたらできた。でも「①で解決したいんだ!」と調べていたらこちらにたどり着きました。

laradockのコンテナはデフォルトでUCT

この差異が今回のエラーの原因では?と思い確認してみました。

公式:https://laradock.io/documentation/#Change-the-timezone

まずコンテナ内で確認。

laradock@245dec687749:/var/www$ date
Thu 01 Jul 2021 02:05:46 AM UTC

UCTでした。

docker-composeを変更する。

laradock/docker-compose.yml

workspace:
      build:
        context: ./workspace
        args:
					(省略)
          - TZ=Asia/Tokyo

再ビルドする

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Starting laradock_mysql_1            ... done
Starting laradock_docker-in-docker_1 ... done
Recreating laradock_workspace_1      ... done
Recreating laradock_php-fpm_1        ... done
Recreating laradock_nginx_1          ... done

$ docker-compose exec --user=laradock workspace bash
laradock@b55f23b3c40c:/var/www$ date
Thu 01 Jul 2021 11:18:27 AM JST
laradock@b55f23b3c40c:/var/www$

再度確認するとJSTになっていました。

そしてエラーも解決しました。

結論

Exception: DateTime::__construct(): Failed to parse time string が出るかつ、Laradock使用の人は、今後の予期せぬエラーを防ぐためにコンテナのTZの確認をした方が良いよというお話でした。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?