因此,我正在尝试为laravel / react应用程序设置环境。 我无法与数据库建立连接。
当我运行composer install或尝试访问我的本地主机时,就会出现此问题。无论哪种方式,我都会收到以下错误。
注意:当我将.env文件中的“ DB_NAME”更改为“ localhost”时,这将返回无法建立连接的错误。但是我能够在黑暗中进行编码并进行迁移,并看到数据显示在我的postgres数据库中。因此必须建立连接。如果我将DB_NAME返回到“ db”,我将不再进行迁移,但是会收到以下错误日志,指出现在可以看到数据库,但无法验证我...我很困惑。
CMD: /var/www # composer install(this is the command I enter, not log feedback)
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Package phpoffice/phpexcel is abandoned, you should avoid using it. Use phpoffice/phpspreadsheet instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
[2018-07-30 21:42:12] development.ERROR: SQLSTATE[08006] [7] FATAL: password authentication failed for user "kyle" {"exception":"[object] (Doctrine\\DBAL\\Driver\\PDOException(code: 7): SQLSTATE[08006] [7] FATAL: password authentication failed for user \"kyle\" at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:50, PDOException(code: 7): SQLSTATE[08006] [7] FATAL: password authentication failed for user \"kyle\" at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:46)
[stacktrace]
#0 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(65): Doctrine\\DBAL\\Driver\\PDOConnection->__construct('pgsql:host=db;d...', 'kyle', 'momspanks', Array)
#1 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(44): Illuminate\\Database\\Connectors\\Connector->createPdoConnection('pgsql:host=db;d...', 'kyle', 'momspanks', Array)
#2 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/PostgresConnector.php(33): Illuminate\\Database\\Connectors\\Connector->createConnection('pgsql:host=db;d...', Array, Array)
#3 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php(183): Illuminate\\Database\\Connectors\\PostgresConnector->connect(Array)
#4 [internal function]: Illuminate\\Database\\Connectors\\ConnectionFactory->Illuminate\\Database\\Connectors\\{closure}()
#5 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(915): call_user_func(Object(Closure))
#6 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(940): Illuminate\\Database\\Connection->getPdo()
#7 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(399): Illuminate\\Database\\Connection->getReadPdo()
#8 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(325): Illuminate\\Database\\Connection->getPdoForSelect(true)
#9 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(657): Illuminate\\Database\\Connection->Illuminate\\Database\\{closure}('select * from i...', Array)
#10 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(624): Illuminate\\Database\\Connection->runQueryCallback('select * from i...', Array, Object(Closure))
#11 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(333): Illuminate\\Database\\Connection->run('select * from i...', Array, Object(Closure))
#12 /var/www/vendor/laravel/framework/src/Illuminate/Database/Schema/PostgresBuilder.php(20): Illuminate\\Database\\Connection->select('select * from i...', Array)
#13 /var/www/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Illuminate\\Database\\Schema\\PostgresBuilder->hasTable('menus')
#14 /var/www/routes/quickadmin.php(5): Illuminate\\Support\\Facades\\Facade::__callStatic('hasTable', Array)
#15 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(394): require('/var/www/routes...')
#16 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(350): Illuminate\\Routing\\Router->loadRoutes('/var/www/routes...')
#17 /var/www/vendor/laravel/framework/src/Illuminate/Routing/RouteRegistrar.php(120): Illuminate\\Routing\\Router->group(Array, '/var/www/routes...')
#18 /var/www/app/Providers/RouteServiceProvider.php(42): Illuminate\\Routing\\RouteRegistrar->group('/var/www/routes...')
#19 [internal function]: App\\Providers\\RouteServiceProvider->map()
#20 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#21 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#22 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#23 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(564): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#24 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(74): Illuminate\\Container\\Container->call(Array)
#25 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(33): Illuminate\\Foundation\\Support\\Providers\\RouteServiceProvider->loadRoutes()
#26 /var/www/app/Providers/RouteServiceProvider.php(28): Illuminate\\Foundation\\Support\\Providers\\RouteServiceProvider->boot()
#27 [internal function]: App\\Providers\\RouteServiceProvider->boot()
#28 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#29 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#30 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#31 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(564): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#32 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(794): Illuminate\\Container\\Container->call(Array)
#33 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(777): Illuminate\\Foundation\\Application->bootProvider(Object(App\\Providers\\RouteServiceProvider))
#34 [internal function]: Illuminate\\Foundation\\Application->Illuminate\\Foundation\\{closure}(Object(App\\Providers\\RouteServiceProvider), 25)
#35 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(778): array_walk(Array, Object(Closure))
#36 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\\Foundation\\Application->boot()
#37 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(206): Illuminate\\Foundation\\Bootstrap\\BootProviders->bootstrap(Object(Illuminate\\Foundation\\Application))
#38 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(297): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#39 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(120): Illuminate\\Foundation\\Console\\Kernel->bootstrap()
#40 /var/www/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#41 {main}
"}
[2018-07-30 21:42:12] development.ERROR: SQLSTATE[08006] [7] FATAL: password authentication failed for user "kyle" (SQL: select * from information_schema.tables where table_schema = public and table_name = menus) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 7): SQLSTATE[08006] [7] FATAL: password authentication failed for user \"kyle\" (SQL: select * from information_schema.tables where table_schema = public and table_name = menus) at /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, Doctrine\\DBAL\\Driver\\PDOException(code: 7): SQLSTATE[08006] [7] FATAL: password authentication failed for user \"kyle\" at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:50, PDOException(code: 7): SQLSTATE[08006] [7] FATAL: password authentication failed for user \"kyle\" at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:46)
[stacktrace]
#0 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(624): Illuminate\\Database\\Connection->runQueryCallback('select * from i...', Array, Object(Closure))
#1 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(333): Illuminate\\Database\\Connection->run('select * from i...', Array, Object(Closure))
#2 /var/www/vendor/laravel/framework/src/Illuminate/Database/Schema/PostgresBuilder.php(20): Illuminate\\Database\\Connection->select('select * from i...', Array)
#3 /var/www/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Illuminate\\Database\\Schema\\PostgresBuilder->hasTable('menus')
#4 /var/www/routes/quickadmin.php(5): Illuminate\\Support\\Facades\\Facade::__callStatic('hasTable', Array)
#5 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(394): require('/var/www/routes...')
#6 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(350): Illuminate\\Routing\\Router->loadRoutes('/var/www/routes...')
#7 /var/www/vendor/laravel/framework/src/Illuminate/Routing/RouteRegistrar.php(120): Illuminate\\Routing\\Router->group(Array, '/var/www/routes...')
#8 /var/www/app/Providers/RouteServiceProvider.php(42): Illuminate\\Routing\\RouteRegistrar->group('/var/www/routes...')
#9 [internal function]: App\\Providers\\RouteServiceProvider->map()
#10 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#11 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#12 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#13 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(564): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#14 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(74): Illuminate\\Container\\Container->call(Array)
#15 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(33): Illuminate\\Foundation\\Support\\Providers\\RouteServiceProvider->loadRoutes()
#16 /var/www/app/Providers/RouteServiceProvider.php(28): Illuminate\\Foundation\\Support\\Providers\\RouteServiceProvider->boot()
#17 [internal function]: App\\Providers\\RouteServiceProvider->boot()
#18 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#19 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#20 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#21 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(564): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#22 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(794): Illuminate\\Container\\Container->call(Array)
#23 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(777): Illuminate\\Foundation\\Application->bootProvider(Object(App\\Providers\\RouteServiceProvider))
#24 [internal function]: Illuminate\\Foundation\\Application->Illuminate\\Foundation\\{closure}(Object(App\\Providers\\RouteServiceProvider), 25)
#25 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(778): array_walk(Array, Object(Closure))
#26 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\\Foundation\\Application->boot()
#27 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(206): Illuminate\\Foundation\\Bootstrap\\BootProviders->bootstrap(Object(Illuminate\\Foundation\\Application))
#28 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(297): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#29 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(120): Illuminate\\Foundation\\Console\\Kernel->bootstrap()
#30 /var/www/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#31 {main}
"}
In Connection.php line 664:
SQLSTATE[08006] [7] FATAL: password authentication failed for user "kyle"
(SQL: select * from information_schema.tables where table_schema = public a
nd table_name = menus)
In PDOConnection.php line 50:
SQLSTATE[08006] [7] FATAL: password authentication failed for user "kyle"
In PDOConnection.php line 46:
SQLSTATE[08006] [7] FATAL: password authentication failed for user "kyle"
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1
答案 0 :(得分:0)
在您的docker-compose.yml
中,请确保使用所需的值声明POSTGRES_USER
和POSTGRES_PASSWORD
,以确保使用以下凭据创建管理员用户:>
db:
image: postgres:9
volumes:
- postgres:/var/lib/postgresql
environment:
POSTGRES_DB: my_database_name
POSTGRES_USER: root
POSTGRES_PASSWORD: password123
# ...
通过使用正确的凭据设置DB_NAME
环境变量,对运行PHP的服务执行相同的操作。您还应该能够将docker-compose服务名称用作数据库的主机名,这里为db
。
答案 1 :(得分:0)
事实证明,这更多是个人基础错误。 创建并直到现在仅在linux操作系统上使用的docker-compose.yml包含以下内容:
PGDATA: /var/lib/postgresql/pgdata # needed as we're using the data folder as mount point
volumes:
- ./docker/db:/var/lib/postgresql
macos上不存在的路径。