Laravel Forge - PHP Artisan SQLState error


Laravel Forge - PHP Artisan SQLState error

我刚刚将我的一个最新应用程序推送到laravel-forge,当我尝试运行php-artisan时,我遇到了这个错误。所有环境变量都在forge中正确设置,所以我不知道这是从哪里来的。

这个应用程序是在laravel 4.2中构建的,据我所见,没有本地配置,本地一切都很好(也可以使用env文件进行本地使用)

{"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}}

数据库配置:

<?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文件:

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

感谢

正如错误所说:

SQLSTATE[HY000][1045]拒绝用户"@'localhost'的访问(使用密码:NO)

数据库配置中一定存在配置错误。您没有为连接指定任何用户,也没有指定密码。

您应该在项目的文件夹中有一个.env.php文件,用于解析值的配置。