Error connecting to database in production environment

405 Views Asked by At

When launching my web app I get a 500 error. The prod.log shows a connection error to the database, and just below that there is a cache.WARNING: Failed to save key in the /var/www/project/var/cache folder. (Not sure if they are related.)

The error says getaddrinfo failed: Temporary failure in name resolution at /var/www/etc.

I've tried changing the configuration of the db connection string from localhost to 127.0.0.1 to the actual IP address and not seeing a difference.

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

        url: '%env(resolve:DATABASE_URL)%'

.env DATABASE_URL=mysql://username:[email protected]:3306/atlas

I'm expecting the configuration to correctly identify the localhost or local ip address and connect to the db.

1

There are 1 best solutions below

0
On

The issue with db error was resolved by created a new repo for the web app and set to run using prod environment variables from the beginning. I can only assume the old files held on to some configuration somewhere that was causing the issue. With the failure to save key error I resolved that by giving read/write permissions to the projects var folder. The Syfmony docs only suggest doing this to the var/log directory however it had problems writing to other var/ directories as well.