jackthedev
jackthedev

Reputation: 417

Laravel Forge - PHP Artisan SQLState error

Ive just pushed one of my latest apps to laravel forge and i am getting this error when i try to run php artisan. All environment variables are set correctly in forge so i have no idea where this is coming from.

This app is built in laravel 4.2 there are no local configs as far as i can see and everything works fine locally (use an env file for local use too)

{"error":{"type":"PDOException","message":"SQLSTATE[HY000] [1045] 
Access denied for user ''@'localhost' (using password: 
NO)","file":"\/home\/forge\/default\/vendor\/laravel\/framework\/src\/Illuminate\/Database\/Connectors\/Connector.php","line":47}}

database config:

<?php

return array(

/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may desire to retrieve records in an
| array format for simplicity. Here you can tweak the fetch style.
|
*/

'fetch' => PDO::FETCH_CLASS,

/*
|--------------------------------------------------------------------------
| 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' => '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' => array(

    'sqlite' => array(
        'driver'   => 'sqlite',
        'database' => __DIR__.'/../database/production.sqlite',
        'prefix'   => '',
    ),

    'mysql' => array(
        'driver'    => 'mysql',
        'host'     => getenv('DB_HOST'),
        'database' => getenv('DB_NAME'),
        'username' => getenv('DB_USERNAME'),
        'password' => getenv('DB_PASSWORD'),
        'unix_socket'   => (App::environment('local') ? '/Applications/MAMP/tmp/mysql/mysql.sock' : ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        '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' => array(

    'cluster' => false,

    'default' => array(
        'host'     => '127.0.0.1',
        'port'     => 6379,
        'database' => 0,
    ),

),

);

ENV FILE:

SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_FROM_ADDRESS=
SMTP_FROM_NAME=
DB_HOST= SERVER IP
DB_NAME= 
DB_USERNAME=
DB_PASSWORD=

Thanks

Upvotes: 1

Views: 653

Answers (1)

Andrius
Andrius

Reputation: 5939

As the error says:

SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)

You must have a misconfiguration in your database config. You're not specifying any user for the connection and no password.

You should have a .env.php file in your project's folder for the configuration to parse the values.

Upvotes: 1

Related Questions