0

I am trying to setup Laravel Sail environment on the server, and after doing the same setup that works locally on my machine along with the .env file

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE="dbname"
DB_USERNAME="sail"
DB_PASSWORD="password"

This is my docker-compose that once again works locally

mysql:
        image: 'mysql:8.0.36'
        command: --default-authentication-plugin=mysql_native_password --skip-grant-tables
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ROOT_HOST: '%'
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 1
        restart: always
        volumes:
            - 'sail-mysql:/var/lib/mysql'
        networks:
            - sail
    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        restart: always
        volumes:
            - 'sail-redis:/data'
        networks:
            - sail
        healthcheck:
            test:
                - CMD
                - redis-cli
                - ping
            retries: 3
            timeout: 5s
networks:
    sail:
        driver: bridge
volumes:
    sail-mysql:
        driver: local

I tried the following

  • Deleted all containers, images and volumes using docker system prune -a
  • Changed the password from default to root
  • Changed both the username and password to root (Removed "" from .env also)
  • When trying to access mysql via sail shell I get the following line ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
  • Chaned DB_HOST in database.php from default to mysql

Note: this is Ubuntu 22.04 server running on digital ocean droplet.

I always get the same error which is

SQLSTATE[HY000] [2002] Connection refused

also docker ps returns a healty mysql container running:

mysql:8.0.36   "docker-entrypoint.s…"   11 minutes ago   Up 11 minutes             0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp                                     nlonetwork_local-mysql-1

1 Answer 1

0

you deleted images and containers but not volumes and network try run sail down then sail up and wait until it finished

Sign up to request clarification or add additional context in comments.

1 Comment

Yes I deleted volumes by running sail down -v. Does not work with build --no-cache and sail up

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.