前提・実現したいこと
作成したLaravelアプリを動かしたい。
発生している問題・エラーメッセージ
ローカルでphp artisan serve
コマンドを打ち、アプリにログインしようとすると
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)
とデータベースからエラーメッセージが表示されます。
該当のソースコード
.env
php
1APP_NAME=stories 2APP_ENV=local 3APP_KEY=base64:nsHYic1BkVCvl4ZwLm3uHGpkUEkVO2UFM+0HNeG1wfc= 4APP_DEBUG=true 5APP_URL=http://laravelstories.work 6 7LOG_CHANNEL=stack 8 9DB_CONNECTION=mysql 10DB_HOST=127.0.0.1 11DB_PORT=3306 12DB_DATABASE=homestead 13DB_USERNAME=homestead 14DB_PASSWORD=secret 15 16BROADCAST_DRIVER=log 17CACHE_DRIVER=file 18QUEUE_CONNECTION=sync 19SESSION_DRIVER=file 20SESSION_LIFETIME=120 21 22REDIS_HOST=127.0.0.1 23REDIS_PASSWORD=null 24REDIS_PORT=6379 25 26MAIL_DRIVER=smtp 27MAIL_HOST=smtp.mailtrap.io 28MAIL_PORT=2525 29MAIL_USERNAME=null 30MAIL_PASSWORD=null 31MAIL_ENCRYPTION=null 32 33 34PUSHER_APP_ID= 35PUSHER_APP_KEY= 36PUSHER_APP_SECRET= 37PUSHER_APP_CLUSTER=mt1 38 39MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 40MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 41
config/database.php
php
1<?php 2 3use Illuminate\Support\Str; 4 5return [ 6 7 /* 8 |-------------------------------------------------------------------------- 9 | Default Database Connection Name 10 |-------------------------------------------------------------------------- 11 | 12 | Here you may specify which of the database connections below you wish 13 | to use as your default connection for all database work. Of course 14 | you may use many connections at once using the Database library. 15 | 16 */ 17 18 'default' => env('DB_CONNECTION', 'mysql'), 19 20 /* 21 |-------------------------------------------------------------------------- 22 | Database Connections 23 |-------------------------------------------------------------------------- 24 | 25 | Here are each of the database connections setup for your application. 26 | Of course, examples of configuring each database platform that is 27 | supported by Laravel is shown below to make development simple. 28 | 29 | 30 | All database work in Laravel is done through the PHP PDO facilities 31 | so make sure you have the driver for your particular database of 32 | choice installed on your machine before you begin development. 33 | 34 */ 35 36 'connections' => [ 37 38 'sqlite' => [ 39 'driver' => 'sqlite', 40 'url' => env('DATABASE_URL'), 41 'database' => env('DB_DATABASE', database_path('database.sqlite')), 42 'prefix' => '', 43 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), 44 ], 45 46 'mysql' => [ 47 'driver' => 'mysql', 48 'url' => env('DATABASE_URL'), 49 'host' => env('DB_HOST', '127.0.0.1'), 50 'port' => env('DB_PORT', '3306'), 51 'database' => env('DB_DATABASE', 'homestead'), 52 'username' => env('DB_USERNAME', 'homestead'), 53 'password' => env('DB_PASSWORD', 'secret'), 54 'charset' => 'utf8', 55 'collation' => 'utf8_unicode_ci', 56 'prefix' => '', 57 'prefix_indexes' => true, 58 'strict' => true, 59 'engine' => null, 60 'options' => extension_loaded('pdo_mysql') ? array_filter([ 61 PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 62 ]) : [], 63 ], 64 65 'pgsql' => [ 66 'driver' => 'pgsql', 67 'url' => env('DATABASE_URL'), 68 'host' => env('DB_HOST', '127.0.0.1'), 69 'port' => env('DB_PORT', '5432'), 70 'database' => env('DB_DATABASE', 'forge'), 71 'username' => env('DB_USERNAME', 'forge'), 72 'password' => env('DB_PASSWORD', ''), 73 'charset' => 'utf8', 74 'prefix' => '', 75 'prefix_indexes' => true, 76 'schema' => 'public', 77 'sslmode' => 'prefer', 78 ], 79 80 'sqlsrv' => [ 81 'driver' => 'sqlsrv', 82 'url' => env('DATABASE_URL'), 83 'host' => env('DB_HOST', 'localhost'), 84 'port' => env('DB_PORT', '1433'), 85 'database' => env('DB_DATABASE', 'forge'), 86 'username' => env('DB_USERNAME', 'forge'), 87 'password' => env('DB_PASSWORD', ''), 88 'charset' => 'utf8', 89 'prefix' => '', 90 'prefix_indexes' => true, 91 ], 92 93 ], 94 95 /* 96 |-------------------------------------------------------------------------- 97 | Migration Repository Table 98 |-------------------------------------------------------------------------- 99 | 100 | This table keeps track of all the migrations that have already run for 101 | your application. Using this information, we can determine which of 102 | the migrations on disk haven't actually been run in the database. 103 | 104 */ 105 106 'migrations' => 'migrations', 107 108 /* 109 |-------------------------------------------------------------------------- 110 | Redis Databases 111 |-------------------------------------------------------------------------- 112 | 113 | Redis is an open source, fast, and advanced key-value store that also 114 | provides a richer body of commands than a typical key-value system 115 | such as APC or Memcached. Laravel makes it easy to dig right in. 116 | 117 */ 118 119 'redis' => [ 120 121 'client' => env('REDIS_CLIENT', 'phpredis'), 122 123 'options' => [ 124 'cluster' => env('REDIS_CLUSTER', 'redis'), 125 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'), 126 ], 127 128 'default' => [ 129 'url' => env('REDIS_URL'), 130 'host' => env('REDIS_HOST', '127.0.0.1'), 131 'password' => env('REDIS_PASSWORD', null), 132 'port' => env('REDIS_PORT', 6379), 133 'database' => env('REDIS_DB', 0), 134 ], 135 136 'cache' => [ 137 'url' => env('REDIS_URL'), 138 'host' => env('REDIS_HOST', '127.0.0.1'), 139 'password' => env('REDIS_PASSWORD', null), 140 'port' => env('REDIS_PORT', 6379), 141 'database' => env('REDIS_CACHE_DB', 1), 142 ], 143 144 ], 145 146]; 147
試したこと
回答2件
あなたの回答
tips
プレビュー