docker-symfony icon indicating copy to clipboard operation
docker-symfony copied to clipboard

Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException

Open Lazur opened this issue 8 years ago • 10 comments

Hi, thanks for your work. I have a problem, which I can't handle by self. All things configured as described in readme. And generally symfony app works, but until I don't try to make a query. Confusing thing is what I can create database, update scheme, but can't perform queries in my app. I checked log files this is the message. I have no idea how to solve it. Could you give any tip about this issue? Thanks.

Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused" at /var/www/symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 103 {"exception":"[object ] (Doctrine\\DBAL\\Exception\\ConnectionException(code: 0): An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused at /var/www/symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:103, Doctrine\\DBAL\\Driver\\PDOException(code: 2002): SQLSTATE[HY000] [2002] Connection refused at /var/www/symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47, PDOException(code: 2002): SQLSTATE[HY000] [2002] Connection refused at /var/www/symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43)"} []

Lazur avatar Sep 19 '17 15:09 Lazur

Hiya,

Could you tell me a bit more about your problem?

So if you can run command through Symfony and you cannot with whatever PHP service, maybe the service don't use the same Connection Provider. Isn't it?

Regards

maxpou avatar Sep 19 '17 16:09 maxpou

I can use creds from env files and enter via pma to database. I can create entity and update schema inside of php container, so mysql works. But symfony app can't connect to database. In parameters.yml I use the creds from env file. Which info do you need?

Lazur avatar Sep 20 '17 05:09 Lazur

I have same problem ... mysql works, creating schema works, i can connect to db via SQL client but via web i can't connect. Same error: "Doctrine\DBAL\Exception\ConnectionException An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused"

themark147 avatar Sep 30 '17 18:09 themark147

Make sure that you have changed app/config/parameters.yml as was mentioned in 4. Prepare Symfony app of installation.

tomasyhy avatar Oct 18 '17 12:10 tomasyhy

Sure I had checked it. Trying to init database for symfony from php container.

root@33c2370b0890:/var/www/symfony# sf doctrine:database:create
                                                                             
  [Doctrine\DBAL\Exception\ConnectionException]                              
  An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused  
                                                                             
  [Doctrine\DBAL\Driver\PDOException]        
  SQLSTATE[HY000] [2002] Connection refused  
                                                                    
  [PDOException]                             
  SQLSTATE[HY000] [2002] Connection refused

But I still can connect from local machine. This goes on mac.

Lazur avatar Oct 29 '17 20:10 Lazur

Same on Ubuntu:


root@7ce187b671e9:/var/www/symfony# sf3 doctrine:database:create
                                                                      
  [Doctrine\DBAL\Exception\ConnectionException]                              
  An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused  
                                 
  [Doctrine\DBAL\Driver\PDOException]        
  SQLSTATE[HY000] [2002] Connection refused  
                  
  [PDOException]                             
  SQLSTATE[HY000] [2002] Connection refused  :

oxydedefer avatar Nov 01 '17 11:11 oxydedefer

I have the same problem

alenn-m avatar Nov 03 '17 17:11 alenn-m

I solved problem by replacing localhost (or 127.0.0.1) by "db". You can see my configuration below:

parameters:
    env(DATABASE_URL): 'mysql://root@db:3306/symfony'

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4

        # With Symfony 3.3, remove the `resolve:` prefix
        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

And in docker-compose file:

db:
        image: mysql
        ports:
            - "3306:3306"
        environment:
          MYSQL_ALLOW_EMPTY_PASSWORD: 1
          MYSQL_DATABASE: symfony

salletti avatar Feb 05 '18 10:02 salletti

Having the same problem. What a nightmare¡ The thing is that i have the configuration as below since the beginning and still not working

parameters: database_host: db database_port: database_name: agency database_user: root database_password: pass mailer_transport: smtp mailer_host: 127.0.0.1 mailer_user: null mailer_password: null secret: ThisTokenIsNotSoSecretChangeIt

this is my docker-compose

version: '3.1'

services: server: container_name: api_server build: context: . dockerfile: php7.Dockerfile image: api_server restart: always ports: - '5015:80' volumes: # - api:/var/www/html - ./server/:/var/www/html # - ./www-data:/var/www/html client: container_name: api_client build: context: . dockerfile: php7.Dockerfile image: api_client restart: always ports: - '5020:80' volumes: - ./client/:/var/www/html

db: container_name: db image: mysql restart: always environment: MYSQL_ROOT_PASSWORD: pass MYSQL_DATABASE: agency volumes: - mysql-data:/var/lib/mysql ports: - '5500:3306'

Any idea?

mgm2030 avatar Mar 29 '18 19:03 mgm2030

parameters:
    database_host: db
    database_port: 5500
    database_name: agency
    database_user: root
    database_password: pass
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    secret: ThisTokenIsNotSoSecretChangeIt

@mgm2030 this should work :)

PyRowMan avatar Mar 30 '18 19:03 PyRowMan