skip to Main Content

I was setting up a Laravel environment. So, I downloaded XAMPP and configured my vhost files accordingly. Then, I setup MySQL and ran the following commands:

  1. composer install
  2. npm install
  3. php artisan (to confirm I had artisan)
  4. php artisan migrate

After, running number 4, I get the following error in the picture.

C:UsersAslamDesktopPfera_applicationpfera-web>php artisan migrate -v

   IlluminateDatabaseQueryException  : SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = forge and table_name = migrations)

  at C:UsersAslamDesktopPfera_applicationpfera-webvendorlaravelframeworksrcIlluminateDatabaseConnection.php: 664
  660:         // If an exception occurs when attempting to run a query, we'll format the error
  661:         // message to include the bindings with SQL, which will make this exception a
  662:         // lot more helpful to the developer instead of just the database's errors.
  663:         catch (Exception $e) {
  664:             throw new QueryException(
  665:                 $query, $this->prepareBindings($bindings), $e
  666:             );
  667:         }
  668:
  669:         return $result;

  Exception trace:

  1   DoctrineDBALDriverPDOException::("SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: YES)")
      C:UsersAslamDesktopPfera_applicationpfera-webvendordoctrinedballibDoctrineDBALDriverPDOConnection.php : 50

Please help!!! Thanks a lot!

PS, here is the database.php file:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | 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'),

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

        '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' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],

        'sqlsrv' => [
            'driver' => 'sqlsrv',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '1433'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer set of commands than a typical key-value systems
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'client' => 'predis',

        'default' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
        ],

    ],

];

Here is my .env file:

## REAL KEY REMOVED FOR PLAIN TEXT TRANSFER
## SEE http://laravel-recipes.com/recipes/283/generating-a-new-application-key FOR GENERATING YOUR OWN KEY, DO THIS BEFORE RUNNING ANY SEEDS
APP_NAME=Pfera
APP_ENV=staging
APP_KEY=base64:E8vEONwbkikyy/7IsRpNg/kakuRy3/JCUjetkpH1EzE=
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=pfera.local

## THESE ARE DB CREDS THAT ARE SPECIFIC TO YOUR OWN DATABASE
## REAL PASSWORD REMOVED FOR PLAIN TEXT TRANSFER
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=forge
DB_USERNAME=forge
DB_PASSWORD=password

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

## REAL MAILGUN SECRET REMOVED FOR PLAINT TEXT TRANSFER
## THIS IS FOR CODE AND MORTAR'S DEVELOPMENT ACCOUNT, UNIQUE CREDENTIALS WILL
## NEED TO BE CREATED FROM YOUR OWN ACCOUNT FOR PRODUCTION, LOCAL DEVELOPMENT,
## AND ONCE THE STAGING ENVIRONMENT IS FULLY TRANSITIONED
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=mg.codeandmortar.com
MAILGUN_SECRET=12345678
MAIL_FROM_NAME="Pfera"
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM="[email protected]"

## THESE ARE ALL VARIABLES FOR SPARK FEATURES NOT IMPLEMENTED IN THIS PHASE
PUSHER_KEY=
PUSHER_SECRET=
PUSHER_APP_ID=

AUTHY_SECRET=

STRIPE_MODEL=AppUser
STRIPE_KEY=
STRIPE_SECRET=

BRAINTREE_MODEL=AppUser
BRAINTREE_ENV=
BRAINTREE_MERCHANT_ID=
BRAINTREE_KEY=
BRAINTREE_SECRET=
## END NON-IMPLEMENTED SPARK VARIABLES

## PAGINATION
HORSES_PER_PAGE=20
EVENTS_PER_PAGE=20
TESTS_PER_PAGE=20
USERS_PER_PAGE=20

## ESTIMATED ESTROUS CYCLE LENGTH IN DAYS
ESTROUS_CYCLE=21

## VARIABLES THE POINT OUT:
## 1) THE PATH TO THE `Rscript` EXECUTABLE TO RUN R CODE
## 2) THE PATH TO THE R CODE REPO
## 3) THE FILENAME OF THE R CODE TO RUN
## NOTE THAT ON THE SERVER WE'RE USING `chroot` SINCE THE R AND PHP UBUNTU
## BINARIES HAD CONFLICTING DEPENDENCIES, THIS IS WHY THE "RELATIVE" PATH FOR
## THE R SCRIPT IS JUST `.`, BECAUSE IT IS WITHIN THE ROOT OF THE CHROOT JAIL.
## THIS WILL ALMOST DEFINITELY NOT BE THE CASE IN LOCAL DEVELOPMENT. FOR LOCAL
## DEVELOPMENT, I WOULD STRONGLY RECOMMEND PROVING `R_PREDICT_PATH` A FULL PATH
## TO THE DIRECTORY THAT CONTAINS THE R CODE (THIS PATH MUST NOT INCLUDE THE R
## FILE ITSELF)
RSCRIPT_BIN="chroot /var/chroot Rscript"
R_PREDICT_PATH=/c/Users/Aslam/Desktop/Pfera_application/pfera-r
R_PREDICT_FILE=predict.R

5

Answers


  1. Laravel is still trying to use the default Forge configuration. You need to open your .env and config/database.php files and configure your connection information for MySQL.

    Your config/database.php file is most likely configured for MySQL already, so I’ll cover mainly your .env file. The .env file exists so you can define different options for your development and production environments.

    In your .env file, configure it like so:

    DB_CONNECTION=mysql
    DB_TEST_DATABASE=database_name
    DB_TEST_USERNAME=mysql_user_with_access_to_the_database
    DB_TEST_PASSWORD=your_super_secure_password
    

    By default, the config/database.php file is set up to pull this information from your .env file. If the .env file doesn’t exist, it has it’s own fallback information.

    Login or Signup to reply.
  2. Your error related configuration of laravel .env with DB

    DB_DATABASE=homestead
    DB_USERNAME=homestead
    DB_PASSWORD=secret

    Login or Signup to reply.
  3. database connection datails are defined in config/database.php file and mysql lines are something like this:

    'host' => env('DB_HOST', 'localhost'),
    

    where the first argument says to get this value from .env file and for any reason if it cant load that information use the second argument.
    so you should define your credentials in both files.

    if nothing helps use

    'host' => 'localhost',
    

    corresponding to each line of database config lines

    Login or Signup to reply.
  4. This is a connection error if you are sure of your database user and password then try to exit of your artisan server in the cli and rerun

    php artisan serve 
    

    if you are not sure of your user name or password and you are using homestead with vagrant

    try the following

    DB_DATABASE=forge
    DB_USERNAME=homestead
    DB_PASSWORD=secret
    

    if you are not sure of your password and username and not using vagrant homestead

    try this

    DB_DATABASE=forge
    DB_USERNAME=root
    DB_PASSWORD=
    
    Login or Signup to reply.
  5. Maybe, if your MySQL password contains this character #, you must adding quote in your password value. Because env file read # character as a comment not a string character. But if you adding quote "" in your env value, then env file can read # character as a string text not a comment

    Example:

    DB_PASSWORD="some-secret-password#"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search