Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.1 Forge-拒绝用户访问SQLSTATE[HY000][1045]''@';本地主机';(使用密码:否)_Php_Laravel - Fatal编程技术网

Php Laravel 5.1 Forge-拒绝用户访问SQLSTATE[HY000][1045]''@';本地主机';(使用密码:否)

Php Laravel 5.1 Forge-拒绝用户访问SQLSTATE[HY000][1045]''@';本地主机';(使用密码:否),php,laravel,Php,Laravel,我刚刚在Laravel 5.1中构建了我的新应用程序,我正在努力将其推向现场。当我尝试安装composer时,我遇到了这个错误 [PDOException] SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO) Script php artisa

我刚刚在Laravel 5.1中构建了我的新应用程序,我正在努力将其推向现场。当我尝试安装composer时,我遇到了这个错误

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

Script php artisan clear-compiled handling the post-install-cmd event returned with an error

[RuntimeException]  
Error Output:       
我正在本地和生产环境中使用环境文件,所以我不知道发生了什么。有什么想法吗

好像我的环境文件没有在forge上被提取

config/database.php

<?php

return [

/*
|--------------------------------------------------------------------------
| 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' => 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' => storage_path('database.sqlite'),
        'prefix'   => '',
    ],

    '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'    => '',
        'strict'    => false,
    ],

    'pgsql' => [
        'driver'   => 'pgsql',
        'host'     => env('DB_HOST', 'localhost'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset'  => 'utf8',
        'prefix'   => '',
        'schema'   => 'public',
    ],

    'sqlsrv' => [
        'driver'   => 'sqlsrv',
        'host'     => env('DB_HOST', 'localhost'),
        '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' => [

    'cluster' => false,

    'default' => [
        'host'     => '127.0.0.1',
        'port'     => 6379,
        'database' => 0,
    ],

],

];

在连接
MySQL
时,确保
MySQL
用户拥有给定ip的所有访问权限。如需进一步参考,请点击以下链接


如果看不到.env文件,就很难确定说什么,但它看起来像是从某处获取用户名-默认值为“forge”,但错误消息中的用户名为空字符串-“”@localhost


检查您的env文件,确保=后面没有空格,并且变量名与数据库配置中的变量名匹配。我还遇到过需要包装密码和其他在“”中具有特殊字符的值的问题。最后,请记住这个案例很重要——我看到过一些问题,其中所有内容都在本地工作,但由于有人更改了变量的案例,所以在dev服务器上失败。我的mac电脑不在乎,但ubuntu服务器在乎

发生这种情况的原因是我使用了forge提供的“安装Repo”功能来安装我的完整项目。现在,由于服务器上没有设置环境,因此在安装时失败

为了解决这个问题,我必须硬编码生产数据库凭据,安装repo,然后创建env文件。然后,一旦这样做了,删除硬编码的凭证(我知道不是很好)

在安装之前设置.env似乎也不起作用。因此,如果从构建之初就将repo安装在服务器上,您就不会遇到这种问题

但是我的项目现在已经正常运行了。谢谢你的回复。

试试这个

一,

二,

三,

四,

五, 确保.env文件的外观如下所示:

APP_ENV=local
APP_DEBUG=true
APP_KEY=YOURAPPKEY

DB_HOST=localhost
DB_DATABASE=YOURDBNAME
DB_USERNAME=YOURPHPMYADMINUSERNAME
DB_PASSWORD=YOURPHPMYADMINPASS
六,


发生这种情况的原因是forge正在您的项目上运行post install命令,并且您可能正在访问某个服务提供商中的数据库,因为可能是要附加到视图的变量,请尝试在服务提供商中注释代码,安装存储库,然后再次向上推送代码,应该可以正常运行

能否显示config/database.php文件?使用db config更新您的环境设置为localhost。即使我删除了该错误,但在.env文件中设置该错误也会覆盖该错误。这真的是一个.env文件吗?我想这是数据库文件。
Try specify environment

php artisan migrate --env=local
Check to see if the MySQL is running by run

mysqladmin -u homestead -p status Enter password: secret

I got

Uptime: 21281 Threads: 3 Questions: 274 Slow queries: 0 Opens: 327 Flush tables: 1 Open tables: 80 Queries per second avg: 0.012

Which mean it's running.
Check MySQL UNIX Socket 
APP_ENV=local
APP_DEBUG=true
APP_KEY=YOURAPPKEY

DB_HOST=localhost
DB_DATABASE=YOURDBNAME
DB_USERNAME=YOURPHPMYADMINUSERNAME
DB_PASSWORD=YOURPHPMYADMINPASS
try changing localhost into 127.0.0.1 in .env DB_HOST or try add your mysql port