【问题标题】:Symfony 5 Fast Track: Database access errorSymfony 5 Fast Track:数据库访问错误
【发布时间】:2021-06-04 14:17:50
【问题描述】:

我正在尝试完成上述教程,但我被困在第 7 步和第 9 步之间的阶段 - 当数据库开始运行时。 在本地服务器上我得到

An exception occurred in driver: SQLSTATE[08006] [7] fe_sendauth: no password supplied

在我的部署服务器上读取数据库时,一切似乎都运行良好: https://akodg6sfgq-gijxpyj6oxpig.eu.s5y.io/admin/ 并进入会议,当我输入评论时https://akodg6sfgq-gijxpyj6oxpig.eu.s5y.io/admin?crudAction=new&crudControllerFqcn=App%5CController%5CAdmin%5CCommentCrudController&menuIndex=2&referrer=https%3A%2F%2Fakodg6sfgq-gijxpyj6oxpig.eu.s5y.io%2Fadmin%3FcrudAction%3Dindex%26crudControllerFqcn%3DApp%255CController%255CAdmin%255CCommentCrudController%26menuIndex%3D2%26signature%3DGrbeBTskRKkJuU_MbS0do5B1M2XowgfTuOLaqpPQl4M%26submenuIndex%3D-1&signature=Rre3TFXH2NDeRLj9W-LKo6RJXR1fbvm37Cu8H04gfQM&submenuIndex=-1它击中了我

Oops! An Error Occurred
The server returned a "500 Internal Server Error".
Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

我不知道这两个是不是同一个问题的一部分,但它是重合的。

我的 .env 配置:

# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
#  * .env                contains default values for the environment variables needed by the app
#  * .env.local          uncommitted file with local overrides
#  * .env.$APP_ENV       committed environment-specific defaults
#  * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=c3aa1e6b44cb8d1cf26c5137433ed753
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7"
DATABASE_URL="postgresql://127.0.0.1:5432/db?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###

.symfony.cloud.yaml:

name: app

type: php:8.0

runtime:
    extensions:
        - apcu
        - mbstring
        - sodium
        - ctype
        - iconv
        - pdo_pgsql
        

#variables:
#    php:
#        # uncomment on PHP 7.4+
#        #opcache.preload: /app/config/preload.php

build:
    flavor: none

disk: 512

web:
    locations:
        "/":
            root: "public"
            expires: 1h
            passthru: "/index.php"



mounts:
    "/var": { source: local, source_path: var }

hooks:
    build: |
        set -x -e

        curl -fs https://get.symfony.com/cloud/configurator | (>&2 bash)
        
        (>&2 symfony-build)

    deploy: |
        set -x -e

        (>&2 symfony-deploy)

relationships:
    database: "db:postgresql"

services.yaml:

db:
    type: postgresql:13
    disk: 1024
    size: S

Docker-compose ps 返回:

       Name                   Command           State            Ports         
--------------------------------------------------------------------------------
guestbook_database_1   docker-entrypoint.sh      Up      0.0.0.0:49153->5432/tcp
                       postgres                          ,:::49153->5432/tcp 

其配置为:

version: '3'

services:
    database:
        image: postgres:13-alpine
        environment:
            POSTGRES_USER: main
            POSTGRES_PASSWORD: main
            POSTGRES_DB: main
        ports: [5432]

有什么想法吗?它在控制器中输入 API 端点后开始。基本上对数据库的任何访问。在我解决这个问题之前,我不想更进一步。

【问题讨论】:

  • 可能只是信息过多,但您的 DATABASE_URL 似乎缺少用户名和密码,这似乎与初始错误消息一致。格式应该是:DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8" 但是在不了解发生了什么的情况下遵循教程可能会非常棘手。某个地方的一个小错误,一切都会爆炸。
  • 我尝试添加 main:main@127.0.0.1/main?... 然后我得到:```驱动程序发生异常:SQLSTATE [08006] [7] FATAL:密码验证失败对于用户“main”致命:用户“main”的密码验证失败```
  • 另外,上面的构造在这里明确建议:“为什么需要在两个不同的地方复制信息?因为在某些云平台上,在构建时,数据库 URL 可能还不知道但是 Doctrine 需要知道数据库的引擎来构建它的配置。所以,主机、用户名和密码并不重要。 symfony.com/doc/current/the-fast-track/en/8-doctrine.html

标签: php postgresql docker symfony docker-compose


【解决方案1】:

谢谢 - 用户名和密码正确。看来数据库给了我错误的端口信息。我已经运行了“symfony run psql”和 \conninfo 并获得了正确的端口

【讨论】:

    【解决方案2】:

    这对于新手来说有点奇怪,但是在 open:local 之后我遇到了同样的问题。 我的问题是,我没有开始我的课程 docker。所以在你的 bash 中当然是在项目目录中。

    1. docker-compose up -d
    2. symfony 服务 -d

    然后everythink工作正常,你可以打开你的本地主机网站;)

    【讨论】:

      猜你喜欢
      • 2022-08-19
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-01
      • 2013-03-18
      • 1970-01-01
      相关资源
      最近更新 更多