symfony 服务器启动时的 PostgreSQL 错误 [英] PostgreSQL errors on symfony server launch

查看:103
本文介绍了symfony 服务器启动时的 PostgreSQL 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 Symfony,我创建了我的项目:symfony new myproject --full在此之后我直接运行 symfony serve

I am learning Symfony, I create my project with : symfony new myproject --full directly after this I run symfony serve

在控制台中我收到这些错误:

in the console I am getting thoses errors :

Tailing Web Server log file (/Users/ben/.symfony/log/cd52af540b09d661e4ffb4f5029da4bbaf3586a9.log)
Tailing PHP-FPM log file (/Users/ben/.symfony/log/cd52af540b09d661e4ffb4f5029da4bbaf3586a9/53fb8ec204547646acb3461995e4da5a54cc7575.log)
                                                                                                                        
 [OK] Web server listening                                                                                              
      The Web server is using PHP FPM 7.3.11                                                                            
      https://127.0.0.1:8000                                                                                            
                                                                                                                        

[Web Server ] Jun  3 23:38:48 |DEBUG  | PHP    Reloading PHP versions 
[Web Server ] Jun  3 23:38:48 |DEBUG  | PHP    Using PHP version 7.3.11 (from default version in $PATH) 
[Application] Jun  3 21:29:59 |CRITICA| REQUES Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused    Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432?" at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96 
[Application] Jun  3 21:29:59 |CRITICA| REQUES Exception thrown when handling an exception (Doctrine\DBAL\Exception\ConnectionException: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused   Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432? at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96) 
[Application] Jun  3 21:29:59 |CRITICA| PHP    Uncaught Exception: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused     Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432? 
[Application] Jun  3 21:37:59 |ERROR  | REQUES Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET https://127.0.0.1:8000/"" at /Users/ben/Desktop/symfonytuto/demo/vendor/symfony/http-kernel/EventListener/RouterListener.php line 136 
[Application] Jun  3 21:38:00 |ERROR  | REQUES Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET https://127.0.0.1:8000/favicon.ico" (from "https://127.0.0.1:8000/")" at /Users/ben/Desktop/symfonytuto/demo/vendor/symfony/http-kernel/EventListener/RouterListener.php line 136 
[Application] Jun  3 21:38:00 |CRITICA| REQUES Exception thrown when handling an exception (Doctrine\DBAL\Exception\ConnectionException: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused   Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432? at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96) 
[Application] Jun  3 21:38:00 |CRITICA| PHP    Uncaught Exception: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused     Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432? 
[Application] Jun  3 21:38:00 |CRITICA| REQUES Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused    Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432?" at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96 
[Application] Jun  3 21:38:00 |CRITICA| REQUES Exception thrown when handling an exception (Doctrine\DBAL\Exception\ConnectionException: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused   Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432? at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96) 
[Application] Jun  3 21:38:00 |CRITICA| PHP    Uncaught Exception: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused     Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432? 
[Web Server ] Jun  3 23:38:48 |INFO   | PHP    listening path="/usr/sbin/php-fpm" php="7.3.11" port=50170
[PHP-FPM    ] Jun  3 23:38:48 |NOTICE | FPM    fpm is running, pid 1240 
[PHP-FPM    ] Jun  3 23:38:48 |NOTICE | FPM    ready to handle connections 

此后,Symfony 的默认页面正确加载,但是当我向 url 添加路由时,例如:https://127.0.0.1:8000/testtt我收到此错误:

After this the Symfony's default page is loading correctly but when I add a route to the url for example : https://127.0.0.1:8000/testtt I'm getting this error :

An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

(应该是这条路线不存在",不是吗?)

(it should be something like 'this route doesnt exist' no ?)

请告诉我如何向您提供有关我的问题的更多信息!

Please tell me how I can give you more info about my problem !

非常感谢!

推荐答案

这个问题经常出现,我认为在问题得到解决之前,我认为答案是合适的.

This question pops up often enough that I think an answer is appropriate until the issue is resolved.

假设您刚刚创建了一个新的 Symfony 网站框架应用程序,添加了一个新控制器并启动了开发服务器.您导航到新路线并抛出异常.要么得到找不到驱动程序"或可以连接到服务器".这当然有点出乎意料,因为您还没有对数据库进行任何操作.

Assume you just created a new Symfony website-skeleton app, added a new controller and started the development server. You navigate to your new route and exceptions are tossed. Either get a 'driver not found' or a 'could connect to server'. Which of course is a bit unexpected since you have not yet done anything with the database.

问题在于 Doctrine 迁移包为 Symfony 的分析器栏提供了一个数据收集器,在开发模式下运行时,该分析器栏会显示在浏览器页面的底部.数据收集器需要连接到数据库才能收集迁移数据.它不关心没有数据库的事实.它只是尝试连接并最终抛出异常.

The problem is that the Doctrine migrations bundle provides a data collector for Symfony's profiler bar that shows up at the bottom of the browser page when running in development mode. The data collector needs to connect to the database in order to collect migrations data. It does not care about the fact that there is no database. It just tries to connect and ends up tossing an exception.

我为此开了一个问题.我仍然不完全确定这是一个功能还是错误.如果您愿意,请随时对此问题发表评论.

I opened an issue on this. I am still not entirely sure if this is a feature or bug. Feel free to comment on the issue if you like.

这是一个相当新的问题,尽管我没有准确跟踪它第一次出现的时间.因此,许多现有的教程和分步指南都没有提到它.将其视为您开发经验的一部分.学习如何阅读异常非常重要.

This is a fairly recent problem though I have not tracked exactly when it first popped up. Hence many existing tutorials and step by step guides do not mention it. Consider it to be part of your development experience. Learning how to read exceptions is quite important.

有几种解决方案.如果您打算使用数据库,请继续创建自己的数据库并调整 DATABASE_URL 以指向它.数据库可以为空.迁移数据收集器只需要能够连接到它.在我的本地开发机器上,我实际上创建了一个名为 db_name 的数据库,只是为了避免出现此错误消息.

There are several solutions. If you plan on using a database then go ahead and create yourself a database and adjust the DATABASE_URL to point to it. The database can be empty. The migration data collector just needs to be able to connect to it. On my local development machine I actually created a database called db_name just to avoid this error message.

第二种解决方案是删除迁移包

A second solution is to just remove the migrations bundle with

composer remove doctrine/doctrine-migrations-bundle

问题就迎刃而解了.如果稍后您需要迁移,则只需使用 composer require 重新安装即可.

And the problem goes away. If later on you need migrations then just use composer require to re-install it.

这篇关于symfony 服务器启动时的 PostgreSQL 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆