I don't know the technical terms of the LAMP stack very well so I will try to explain myself as much as I can. I have my project in my local Ubuntu (running on Windows 10 pro). I ran docker from WSL and I edited the default Laravel Sail docker-compose file.
my env file is like this:
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=new_cms_system_db
DB_USERNAME=root
DB_PASSWORD=
and this is my docker-compose MySQL part:
db:
image: 'mysql:5.7'
container_name: db
ports:
- '3306:3306'
environment:
MYSQL_DATABASE: mysql
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MYSQL_USER: sail
MYSQL_PASSWORD: 123
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
if I use "DB_HOST" as "db," then I have got no problems reaching the database from the website but then I can't use "PHP artisan migrate" as I get SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known error.
So I change "DB_HOST" to 0.0.0.0, then I can migrate but I can't reach the database from the website.
What should I do to solve this problem so I can both reach the database from the terminal and the website?
DB_HOST=db? Isn't the simple solution just to doDB_HOST=127.0.0.1since you're hosting it locally?MYSQL_DATABASE: mysqlbut then in your .env you're doingDB_DATABASE=new_cms_system_db.MYSQL_DATABASE: new_cms_system_db