Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mtvs_dev's avatar

[PDOException] Access denied for user 'forge'@'localhost'

When I try to migrate the database tables, I get the following error:

[PDOException] SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using pa ssword: NO)

I created the .env file and just change the DB_DATABASE and the APP_KEY, I don`t know where the heck forge comes from?

0 likes
8 replies
bestmomo's avatar

Set your values in .env :

DB_HOST=localhost
DB_DATABASE=mybase
DB_USERNAME=myname
DB_PASSWORD=mypassword

But are you on forge ?

bobbybouwmann's avatar

Forge is the default in config/database.php

        'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => 'sebwite_',
            'strict'    => false,
        ],

Like bestmomo said, set the values in your .env file

3 likes
mtvs_dev's avatar

@bobbyborisov thanks at least i know where it comes from but as i said i've created the .env file, I`l double check that

arabsight's avatar
Level 10

in bootstrap/app.php did you uncomment this line:

Dotenv::load(__DIR__.'/../');
1 like
bashy's avatar

Sounds like it's not pulling in the .env file (PHP environments). Try display one to see if it's being set?

sitesense's avatar

@mtvs_dev Are you trying to run the migration from the local command line?

You'll need to SSH into the VM and run it from there, otherwise Artisan will be trying to connect to a local database which probably doesn't exist.

_Marco_'s avatar

This happened to me before. Make sure that in your database.php in config your default connection name is the same as in your .env.

database.php:

	 /*
  |--------------------------------------------------------------------------
  | Default Database Connection Name
  |--------------------------------------------------------------------------
  |
  | Here you may specify which of the database connections below you wish
  | to use as your default connection for all database work. Of course
  | you may use many connections at once using the Database library.
  |
   */

  'default'     => env('DB_CONNECTION', 'mysql'),

.env:

##############################################################
# Database Configuration
##############################################################

DB_CONNECTION=mysql
DB_HOST=mybase
DB_USERNAME=myname
DB_PASSWORD=mypassword

Please or to participate in this conversation.