docker-symfony
docker-symfony copied to clipboard
Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException
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)"} []
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
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?
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"
Make sure that you have changed app/config/parameters.yml as was mentioned in 4. Prepare Symfony app of installation.
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.
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 :
I have the same problem
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
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?
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 :)