#config:cache & config:clear cause two different issues

4 messages · Page 1 of 1 (latest)

desert gyro
#

I have a two page app.

  • Landing page as no queries.
  • Second page has a single query using a very basic eloquent model:
    $claim = Claims::where('username', $username)->first();

On the second page, I receive SQLSTATE[HY000] [2002] Connection refused

I know typically this is an issue with the DB credentials in the .env, so I've changed them to match another project that works locally (both apps on a very basic Docker image).

When I run php artisan config:cache I get:

file_put_contents(storage/framework/sessions/pKiOoJAXNAp2xe6scQOiaH8RU70iZcbgJvU6RmFl): Failed to open stream: No such file or directory

If I run php artisan config:clear I get SQLSTATE[HY000] [2002] Connection refused

Can someone help explain why those are causing to vastly different errors? (I've run both commands from inside and outside of the Docker container and the behavior is reproducible).

topaz canyon
#

Do you get these errors when executing those commands, or do you see the errors after running the commands successfully and then visiting a page?

desert gyro
#

No errors executing said commands, only after.

With that said. I SSH'd into the Docker Image and manually changed my .env to the following:

DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=search
DB_USERNAME=root
DB_PASSWORD=root

whereas previously it was

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=search
DB_USERNAME=root
DB_PASSWORD=root

My docker-compose.yml file has the following for MySQL:

  db:
    image: mariadb
    restart: on-failure
    volumes:
      - ./storage/docker/mariadb:/var/lib/mysql
    ports:
      - "3305:3306"
    hostname: mariadb
    environment:
      - MYSQL_DATABASE=search
      - MYSQL_USER=root
      - MYSQL_PASSWORD=root
      - MYSQL_ROOT_PASSWORD=root
    networks:
      doc-network:

Solution: Make sure your DB_HOST of your .env file inside Docker matches the hostname of your docker-compose.yml file.

topaz canyon
#

Okay, so if it's after that makes complete sense. Without config caching it reads directly from the env, thus it uses the values defined there, which results in an error connecting. Caching the config writes the config to a temporary file in the storage directory, later on it tries to read that file, but that file doesn't exist (somehow?). So it looks like your docker setup might need to be updated, I'm not all to familiar with Docker, but it sounds like the containers only partially have the required files