Access denied for user 'root'@'localhost' (using password: NO)
Suggests that maybe an earlier config without a was cached when you did not have DB_PASSWORD set in .env - try clearing the cache
php artisan config:clear
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi! I'm a noob when it comes to Laravel. I recently tried to deploy a project on an AWS EC2 server (LAMP). After deploying, when I try to run php artisan migrate i get the following error.
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
The following is my .env file
APP_NAME="myApp" APP_ENV=local APP_KEY=base64:UTBgGqkc11OYbnGGJVe32xFluhFeNw288oH0UcmMYqU= APP_DEBUG=true APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=islarncn_irh DB_USERNAME=root DB_PASSWORD=secret
The following is my /myApp/config/database.php file
'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'prefix_indexes' => true, 'strict' => false, 'engine' => null, 'options' => extension_loaded('pdo_mysql') ? array_filter([ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), ]) : [], ],
Thanks in advance.
Access denied for user 'root'@'localhost' (using password: NO)
Suggests that maybe an earlier config without a was cached when you did not have DB_PASSWORD set in .env - try clearing the cache
php artisan config:clear
Please or to participate in this conversation.