Php Symfony 4+;Postgresql:服务器仍在尝试连接到;“本地主机”;数据库,即使我更改了doctor.yaml和.env中的值

Php Symfony 4+;Postgresql:服务器仍在尝试连接到;“本地主机”;数据库,即使我更改了doctor.yaml和.env中的值,php,postgresql,symfony,doctrine,virtual-machine,Php,Postgresql,Symfony,Doctrine,Virtual Machine,我最近在一台运行应用程序的虚拟机上部署了我的symfony应用程序,该虚拟机连接到我运行Postgresql server的主机。我正在尝试更改symfony应用程序中的数据库url(我从将env中的数据库url更改为开始) pdo_pgsql://postgres:*password here*@192.168.122.1:5432/postgres?serverVersion=11&charset=utf8 但是,在服务器启动并访问某个页面时,我发现错误: The We

我最近在一台运行应用程序的虚拟机上部署了我的symfony应用程序,该虚拟机连接到我运行Postgresql server的主机。我正在尝试更改symfony应用程序中的数据库url(我从将env中的数据库url更改为开始)

pdo_pgsql://postgres:*password here*@192.168.122.1:5432/postgres?serverVersion=11&charset=utf8
但是,在服务器启动并访问某个页面时,我发现错误:

      The Web server is using PHP CGI 7.3.21                                                                            
      http://127.0.0.1:8000                                                                                             
                                                                                                                        

[Web Server/PHP ] Aug 18 14:03:53 |ERROR| PHP    Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused 
[Web Server/PHP ] Aug 18 14:03:53 |INFO | PHP       Is the server running on host "localhost" (::1) and accepting 
[Web Server/PHP ] Aug 18 14:03:53 |INFO | PHP       TCP/IP connections on port 5432? 
[Web Server/PHP ] Aug 18 14:03:53 |INFO | PHP    could not connect to server: Connection refused 
[Web Server/PHP ] Aug 18 14:03:53 |INFO | PHP       Is the server running on host "localhost" (127.0.0.1) and accepting 
[Web Server/PHP ] Aug 18 14:03:53 |INFO | PHP       TCP/IP connections on port 5432?" at /symfony/dynamic_form_generator/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 73 
[Web Server/PHP ] Aug 18 14:03:53 |INFO | PHP     
[Web Server/PHP ] Aug 18 14:03:53 |ERROR| SERVER POST (500) /login host="127.0.0.1:8004" ip="127.0.0.1" scheme="https"
这清楚地表明,无论出于什么原因,Doctrine/PHP dba stuff都在尝试连接到localhost:5432。我在网上查过,提到的文件只有.env、Doctrine.yaml和parameters.yml(我的项目结构中甚至没有这些文件)

我已经清除了缓存两次,但大多数时候,当我试图清除它时,我得到了错误

[root@localhost dynamic_form_generator]# php bin/console cache:clear
*
 // Clearing the cache for the prod environment with debug false                                                        

 ! [NOTE] For better performances, you should move the cache and log directories to a non-shared folder of the VM.      


In Filesystem.php line 176:
                                                                                                                                                                             
  Failed to remove directory "/symfony/dynamic_form_generator/var/cache/prod/doctrine": rmdir(/symfony/dynamic_form_generator/var/cache/prod/doctrine): Directory not empty  
                                                                                                                                                                             

cache:clear [--no-warmup] [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>

和.env:(重要的部分,其余是评论)

###>symfony/frameworkbundle###
APP_ENV=prod
APP_SECRET=8cce45f8d9c607e2a1a371349617970c
#受信任的_代理=127.0.0.0/8,10.0.0.0/8172.16.0.0/12192.168.0.0/16/192.168.122.1
#TRUSTED_HOSTS='^(localhost | example\.com)$'
###条令/条令束###
#格式说明见https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-使用-a-url
#对于SQLite数据库,请使用:“SQLite:///%kernel.project\u dir%/var/data.db”
#对于PostgreSQL数据库,请使用:“postgresql://db_user:db_password@127.0.0.1:5432/db_name?服务器版本=11&charset=utf8“
#重要提示:必须在此处或config/packages/doctor.yaml中配置服务器版本
数据库URL=pdo_pgsql://postgres:*此处的密码*@192.168.122.1:5432/postgres?serverVersion=11&charset=utf8
DB_USERNAME=postgres
DB_CONNECTION=pgsql
DB_HOST=192.168.122.1
数据库=postgres
DB_PASSWORD=*此处的密码*
###<条令/条令束###
###>内尔米奥/科尔斯束###
CORS|u ALLOW_ORIGIN=^https?:/(本地主机| 127.0.0.1 | 192.168.122.1)(:[0-9]+)$
###
  • 这里的密码*是密码应该在的地方。我做错了什么

编辑:修复了粘贴文件内容中的小错误。

在对配置进行了一整天的混乱之后,我尝试运行
php-bin/console-debug:config-doctrine | grep localhost
查看如果该条令覆盖了我的设置,并且确实存在一个隐藏参数“host:localhost”,会出现什么问题。 所以我所要做的就是回到doctrine yaml文件,添加一行“host:192.168.122.1”

看起来是这样的:


    dbal:
        driver: 'pdo_pgsql'
        charset: utf8
        url: pdo_pgsql://postgres:* password here *@127.0.0.1:5432/postgres?serverVersion=11&charset=utf8
        user:     "%env(resolve:DB_USERNAME)%"
        password: "%env(resolve:DB_PASSWORD)%"
        host: 192.168.122.1
我希望这解决了任何人谁有它的问题

###> symfony/framework-bundle ###
APP_ENV=prod
APP_SECRET=8cce45f8d9c607e2a1a371349617970c
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16/192.168.122.1
#TRUSTED_HOSTS='^(localhost|example\.com)$'
###< 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
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11&charset=utf8"
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
DATABASE_URL=pdo_pgsql://postgres:* password here *@192.168.122.1:5432/postgres?serverVersion=11&charset=utf8
DB_USERNAME=postgres
DB_CONNECTION=pgsql
DB_HOST=192.168.122.1
DB_DATABASE=postgres
DB_PASSWORD= * password here *
###< doctrine/doctrine-bundle ###

###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1|192\.168\.122\.1)(:[0-9]+)?$
###< nelmio/cors-bundle ###
~                                 

    dbal:
        driver: 'pdo_pgsql'
        charset: utf8
        url: pdo_pgsql://postgres:* password here *@127.0.0.1:5432/postgres?serverVersion=11&charset=utf8
        user:     "%env(resolve:DB_USERNAME)%"
        password: "%env(resolve:DB_PASSWORD)%"
        host: 192.168.122.1