質問を読んでくれてありがとう、ServerFault、Stackoverflow、AskUbuntuで質問を読んで1週間以来、このエラーに取り組んでいましたが、問題を理解できませんでした。
私が持っています
GitHubから複製した既存のプロジェクトがあり、すべてが順調に進んでいますが、データベースに接続する必要があるページに移動すると(ログインを試みるなど)、次のエラーが発生します。
PDOException(1045)ヘルプ
SQLSTATE [HY000] [1045]ユーザー 'Homestead' @ 'localhost'のアクセスが拒否されました(パスワードを使用:YES)
プロジェクトに.envファイルがあり、名前を付けました。env.local.phpこれはファイルです:
<?php
/**
* Variables de entorno .env.php
* Si se requiere cargar otros valores para un entorno diferente al de produccion (local, development, etc.)
* cree un archivo con el nombre asi:
* - local => .env.local.php
* - development => .env.development.php
*/
return [
'DATABASE_NAME' => 'DATABASE_NAME',
'DATABASE_USER' => 'DATABASE_USER',
'DATABASE_PASSWORD' => 'DATABASE_PASSWORD',
/*
* social
* '$RED$_IDENTIFIER' => '',
* '$RED$_SECRET' => '',
* '$RED$_CALLBACK_URI' => '',
*/
'GOOGLE_IDENTIFIER' => 'GOOGLE_IDENTIFIER',
'GOOGLE_SECRET' => 'GOOGLE_SECRET',
'GOOGLE_CALLBACK_URI' => 'GOOGLE_CALLBACK_URI',
'FACEBOOK_IDENTIFIER' => 'FACEBOOK_IDENTIFIER',
'FACEBOOK_SECRET' => 'FACEBOOK_SECRET',
'FACEBOOK_CALLBACK_URI' => 'FACEBOOK_CALLBACK_URI',
/**
* PayU configs
* PAYU_TEST: 1 = Modo prueba, 0 = Modo Produccion
*/
'PAYU_MACRO_ACCOUNT_ID' => 654321,
'PAYU_MICRO_ACCOUNT_ID' => 123456,
'PAYU_MERCHANT_ID' => 123456,
'PAYU_API_KEY' => 'ABCabc123DEFdef456GHIghi78',
'PAYU_API_LOGIN' => '123abc456def789',
'PAYU_TEST' => 1,
];
/var/www/kinbuweb/app/config/local/database.phpにdatabase.phpファイルがあります/ config/localパスを強調表示します私が読んでいるのは、ローカル環境がある場合の構成です(そして、ファイルに.env。local。phpという名前を付けました)。パス:
<?php
return [
/*
|--------------------------------------------------------------------------
| 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' => [
'mysql' => [
'driver' => 'mysql',
'Host' => 'localhost',
'database' => 'Homestead',
'username' => 'Homestead',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
'pgsql' => [
'driver' => 'pgsql',
'Host' => 'localhost',
'database' => 'Homestead',
'username' => 'Homestead',
'password' => 'secret',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
],
];
一方、ローカルフォルダー(パス:/ var/www/kinbuweb/app/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' => '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' => __DIR__ . '/../database/production.sqlite',
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'Host' => 'localhost',
'database' => $_ENV['DATABASE_NAME'],
'username' => $_ENV['DATABASE_USER'],
'password' => $_ENV['DATABASE_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
'pgsql' => [
'driver' => 'pgsql',
'Host' => 'localhost',
'database' => 'forge',
'username' => 'forge',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'Host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'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,
],
],
];
次のように、ローカル(/var/www/kinbuweb/app/config/local/database.php)database.php構成の資格情報を使用します。
<?php
/**
* Variables de entorno .env.php
* Si se requiere cargar otros valores para un entorno diferente al de produccion (local, development, etc.)
* cree un archivo con el nombre asi:
* - local => .env.local.php
* - development => .env.development.php
*/
return [
'DATABASE_NAME' => 'Homestead',
'DATABASE_USER' => 'Homestead',
'DATABASE_PASSWORD' => 'secret',
'GOOGLE_IDENTIFIER' => 'GOOGLE_IDENTIFIER',
'GOOGLE_SECRET' => 'GOOGLE_SECRET',
'GOOGLE_CALLBACK_URI' => 'GOOGLE_CALLBACK_URI',
'FACEBOOK_IDENTIFIER' => 'FACEBOOK_IDENTIFIER',
'FACEBOOK_SECRET' => 'FACEBOOK_SECRET',
'FACEBOOK_CALLBACK_URI' => 'FACEBOOK_CALLBACK_URI',
'PAYU_MACRO_ACCOUNT_ID' => 654321,
'PAYU_MICRO_ACCOUNT_ID' => 123456,
'PAYU_MERCHANT_ID' => 123456,
'PAYU_API_KEY' => 'ABCabc123DEFdef456GHIghi78',
'PAYU_API_LOGIN' => '123abc456def789',
'PAYU_TEST' => 1,
];
次のように、ローカルフォルダー内のデータベース構成にポートを集約します。
<?php
return [
'connections' => [
'mysql' => [
'driver' => 'mysql',
'Host' => 'localhost:3306',
'database' => 'Homestead',
'username' => 'Homestead',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
'pgsql' => [
'driver' => 'pgsql',
'Host' => 'localhost',
'database' => 'Homestead',
'username' => 'Homestead',
'password' => 'secret',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
],
];
そして、私は同じエラーを受け取りましたが:PDOException(1045)HELP
SQLSTATE [HY000] [1045]ユーザー 'Homestead' @ 'localhost'のアクセスが拒否されました(パスワードを使用:YES)
私と一緒にこれを解決できるアイデアはありますか?ありがとう
データベースのmysqlにユーザー「Homestead」の特権を追加してみてください。
Mysqlにログインし、次のような特権を追加します。
mysql -u root -p
MySQLのパスワードを入力してください
mysql > grant all privileges on Homestead *.* to 'Homestead'@'localhost' identified by 'password';
ここでの「パスワード」はdatabase.phpにあります
ローカル環境にいる場合、database.phpのパスは次のとおりです。
yourporjectfolder/app/config/local
mysql > FLUSH PRIVILEGES;