简体   繁体   English

Laravel用户myproject @ localhost的访问被拒绝

[英]Laravel access denied for user myproject@localhost

I'm using Laravel 4.2 and I'm usinh ssh to log into server. 我正在使用Laravel 4.2,并且正在使用ssh登录服务器。 I'm trying to make anew migration and I ran: 我正在尝试重新迁移,然后我跑了:

php artisan make:migration create_logs_table --create=logs

but i'm getting this error: 但我收到此错误:

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

I haven't changed my env file - database, username and password are still the same. 我尚未更改我的环境文件-数据库,用户名和密码仍然相同。 When I use command line and try to create a new migration, I got this error. 当我使用命令行并尝试创建新的迁移时,出现此错误。 Why I get this error for user myproject -> my username is another - this is the name of the project. 为什么我的用户myproject出现此错误->我的用户名是另一个-这是项目的名称。

Thanks! 谢谢!

Well CLI in Laravel 4 can be tricky. Laravel 4中的CLI可能很棘手。 Despite of .env file you could also have different enviroment in web and in CLI set. 尽管有.env文件,您在Web和CLI集中也可以具有不同的环境。

So... first of all if you have for example local enviroment - in the .env file: 所以...首先,如果您在.env文件中有例如本地环境,请执行.env操作:

export APP_ENV=local

but this is not enough. 但这还不够。 You have to open your bootstrap/start.php file and set your machine to specify enviroment: 您必须打开bootstrap/start.php文件并将机器设置为指定环境:

$env = $app->detectEnvironment(function() use ($app){
    $env = array_get($_SERVER, 'APP_ENV');
    if(empty($env)){
        $envs = [
            'local' => ['your_machine_name'],
        ];
        $env = $app->detectEnvironment($envs);
    }
    return $env;
});

Be sure that you have this all set and you're working on good enviroment. 确保已经准备好所有这些,并且您在良好的环境中工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM