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 1 year has passed since last update.

composer installでSQLSTATE[HY000] [2002] Connection refused 

Last updated at Posted at 2022-12-24

環境

OS : mac
仮想環境 : docker (Linux, apache(debian), mysql, php )

背景

docker環境を使って複数サイトをローカルで見れるようにしたい
docker-compose exec サービス名 bash
でdockerコンテナ内に入りgithubからpullしてきたプロジェクトのディレクトリで
composer installしたところ
以下エラーが出てしまった

In Connection.php line 664:

  SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_s
  chema.tables where table_schema = XXX and table_name = ABC)


In PDOConnection.php line 31:

  SQLSTATE[HY000] [2002] Connection refused


In PDOConnection.php line 27:

  SQLSTATE[HY000] [2002] Connection refused

試したこと

 いろいろと検索していたら.envのファイルのdb_host の記述が誤っていたらしい。
「DB_HOST 127.0.0.1」とそれまで記載していた。
どうやらdockerを使う場合は.envのdb_hostにはコンテナ名にしないといけない模様。

スクリーンショット 2022-12-24 10.09.24.png

以下のように設定。

.env
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
・
・

そしてまた
composer install を実行
これまで出ていたエラーは無くなった

今度は次のエラーが出たが、、、
これは単純に.envで記載したDBがmysql上にないのだろう。。

> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

In Connection.php line 664:

  SQLSTATE[HY000] [1049] Unknown database 'test' (SQL: select * from inf
  ormation_schema.tables where table_schema = XXX and table_name = ABC)


In PDOConnection.php line 31:

  SQLSTATE[HY000] [1049] Unknown database 'test'


In PDOConnection.php line 27:

  SQLSTATE[HY000] [1049] Unknown database 'test'

docker-compose exec db bash でmysqlのコンテナに入って
データベースを作成。

exitでコンテナから出て、またdocker-compose exec サービス名 bash
サービス用のコンテナに入り、
composer install を実行

以下で表示され、無事composerのインストールが完了しました!!

> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: aws/aws-sdk-php-laravel
Discovered Package: barryvdh/laravel-dompdf
Discovered Package: barryvdh/laravel-snappy
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: chumper/zipper
Discovered Package: fideloper/proxy
Discovered Package: jenssegers/agent
Discovered Package: kris/laravel-form-builder
Discovered Package: laravel-notification-channels/apn
Discovered Package: laravel-notification-channels/fcm
Discovered Package: laravel/nexmo-notification-channel
Discovered Package: laravel/passport
Discovered Package: laravel/slack-notification-channel
Discovered Package: laravel/tinker
Discovered Package: laravelcollective/html
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: xethron/migrations-generator
Package manifest generated successfully.
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?