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 DoctrineDBALExceptionConnectionException: "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 (DoctrineDBALExceptionConnectionException: 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 SymfonyComponentHttpKernelExceptionNotFoundHttpException: "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 SymfonyComponentHttpKernelExceptionNotFoundHttpException: "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 (DoctrineDBALExceptionConnectionException: 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 DoctrineDBALExceptionConnectionException: "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 (DoctrineDBALExceptionConnectionException: 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 !
3
Answers
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
And the problem goes away. If later on you need migrations then just use composer require to re-install it.
I have another solution that solves the problem without having to remove the package with
composer remove ...
.comment out
DoctrineBundleMigrationsBundleDoctrineMigrationsBundle::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.
If the issue appears when you want to access the localhost…/lucky/number, go to .env file under the your "folder name" and uncomment this line:
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
And the rest of them with mySQl and Postgres, comment them.
Hope it works for you. 🙂