4

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 

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 !

Thanks a lot !

9
  • 1
    The Doctrine Migrations Bundle requires an actual database connection in dev mode for the profile bar. Either remove the bundle (you can re-install later if you need it) or create a database and adjust the credentials. By the way, what you call the 'default page' comes up when no routes are defined. Once you define one then you will start getting these sorts of errors. Commented Jun 4, 2021 at 0:21
  • 1
    Hi @Cerad thank you for your answer, I am following a Symfony course on Udemy.com and he didnt create any database, or removed a bundle and his error was "this route doesnt exist" or something like that.. so it's weird that I have to do something he didn't for this to work properly.. But if there is no choice can you please give me more details about your solutions (how to proceed) Thanks a lot for your help Commented Jun 4, 2021 at 8:06
  • by the way my project is not using a database yet, i litteraly just created the project and launvhed the server Commented Jun 4, 2021 at 8:08
  • Just do a 'composer remove doctrine/migrations' and the problem will go away. You will get this error in development mode regardless of if you are using a database or not. Just one of those things. Commented Jun 4, 2021 at 12:00
  • 1
    @Cerad removing doctrine/doctrine-migrations-bundle worked but, can you explain to me why i needed to remove it and not the teacher of the course ? Also maybe I will need it in the future ? Thanks for your help ! Commented Jun 4, 2021 at 13:09

2 Answers 2

11

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

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.

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.

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

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

Sign up to request clarification or add additional context in comments.

3 Comments

This should be added in the documentation "Create your First Page" or fixed quickly because it is very confusing and frustating to get this error from the first documentation exercice. Also is it just me or "driver not found" doesnt help to understand what's happening ?
A fix has actually been made. Just has not been released yet. The actual messages do come from deep in the heart of the database system and are reasonably accurate. To me at least it's just a surprise to get database errors when you are not using a database.
When I run composer remove doctrine/doctrine-migrations-bundle it just results in "In ArrayLoader.php line 44: Unknown package has no name defined" when reloading the page. Just running through the "create your first page" tutorial and experiencing this unexpected roadblock.
0

I have another solution that solves the problem without having to remove the package with composer remove ....

comment out Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], in /config/bundles.php

Then move /config/packages/doctrine_migrations.yaml up one directory so it's not longer trying to be included.

This may be a little less intimidating for new developers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.