I recently attempted to deploy my Symfony application to a server hosted with Ionos. I've configured the database parameters in both the .env file and the doctrine.yaml file, but I'm encountering an error when trying to connect to the database.
Here are the details of my configuration:
.env:
DATABASE_URL="mysql://dbu53*****:password@db50146*****.hosting-data.io:3306/dbs121*****"
doctrine.yaml File:
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '8.0'
charset: utf8mb4
host: 'db50146*****.hosting-data.io'
port: 3306
user: 'dbu53*****'
password: 'password'
dbname: 'dbs121*****'
url: '%env(DATABASE_URL)%'
However, when I attempt to connect to the database, I get the following error:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Unknown host.
I suspect that the issue may be related to how I've configured the database connection parameters, but I'm not sure about the source of this error. Are there any obvious errors in my configuration? Is there something specific I should check?
I appreciate any help that can be provided in resolving this issue with Symfony's remote database connection.
That error implies that your host was not resolved by the dns. Sometimes that's because your username or password contains a
@sign, which need to be escaped first. It could be in some cases the'and"also need to be escaped.If you use a doctrine url, you don't have to specify all the other properties like
driver,server_version,charset,host,port,user,passwordanddbname. These can all be derived from the url. Not all environments are the same, so you can configure these in one url.Example: