Laravel Forge - PHP Artisan SQLState错误

时间:2015-10-29 08:41:01

标签: php laravel

我刚推送了一个最新的应用程序到laravel forge,当我尝试运行php artisan时,我收到此错误。所有环境变量都在伪造中正确设置,因此我不知道它来自何处。

这个应用程序是在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 FILE:

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

由于

1 个答案:

答案 0 :(得分:1)

正如错误所说:

  

SQLSTATE [HY000] [1045]拒绝用户访问&#39;&#39; localhost&#39; (使用   密码:否)

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

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