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

windows,homestead,laravel環境にphpmyadminを接続しようとしたらハマった。

Last updated at Posted at 2020-01-13

環境

"php": "^7.1.3",
"laravel/framework": "5.8.*",
"windows10 home",
"vagrant 2.26",
"virtialBox 5.2"

下記サイトを参考にして、タイトルの環境化でsqliteからphpmyadminを接続しなおしてみました。
https://qiita.com/r-kawanishi/items/f12741bebd398d791114
基本的には上記サイトのまんまやったのですが、少し躓いたので備忘録を残しておきます。phpmyadminを開き、php artisan migrate:refreshをたたくと以下のエラーを吐きました。

エラー文↓

$ php artisan migrate:refresh

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] 対象のコンピューターによ
って拒否されたため、接続できませんでした。
 (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations and table_type = 'BASE TABLE')

  at C:\Users\retur\dev_workspace\laravel\practice\code\laravelyoutube\vendor\laravel\framework\src\Illuminate\Database\Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format 
the error
    666|         // message to include the bindings with SQL, which will make this exception a
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673| 

  Exception trace:

  1   PDOException::("SQLSTATE[HY000] [2002] 対象のコンピューターによって拒否されたため 
、接続できませんでした。
")
      C:\Users\retur\dev_workspace\laravel\practice\code\laravelyoutube\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

  2   PDO::__construct()
      C:\Users\retur\dev_workspace\laravel\practice\code\laravelyoutube\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

  Please use the argument -v to see more details.

この 「対象のコンピューターによって拒否されたため 、接続できませんでした。」
を参考にググると以下のサイトが https://teratail.com/questions/158477
それを参考にして、.envファイルを編集しました。

.env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:VTiFYU4BPohmbw0xMJdXiGGCDfkDrM0MzpiTJW9cxBk=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
# DB_HOST=127.0.0.1
DB_HOST=192.168.10.10 //★hostの番号を変える上記の127.0.0.1だとエラーになりました。
DB_PORT=3306
DB_DATABASE=homestead // laravel5.8だとlaravelになっている。
DB_USERNAME=homestead //laravel5.8だとrootになっているので注意
DB_PASSWORD=secret  //laravel5.8だと空なので注意

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=cookie
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

Homestead.yaml

ip: 192.168.10.10
memory: 2048
cpus: 2
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
    - ~/.ssh/id_rsa
folders:
    -
        map: 'C:\Users\retur\dev_workspace\laravel\practice\code\laravel-document'
        to: /home/vagrant/code
sites:
    -
        map: homestead.test
        to: /home/vagrant/code/public
    -   
        map: homestead.phpmyadmin
        to: /usr/share/phpmyadmin
databases:
    - homestead
    - laravel70 //★ここを編集しました。
features:
    -
        mariadb: false
    -
        ohmyzsh: false
    -
        webdriver: false
name: laravel-document
hostname: laravel-document
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?