I download from https://github.com/luciddreamz/laravel Laravel for openshift then upload over my repository over github. This code for connect to database not work. The prob
If someone is facing this issue in the hosting services like hostgator or any thing else then you should have to change the value of "localhost" to the relative values which is provided by the hosting provider. In my case it is available in the "phpmyadmin" tab of "cpanel" at the top right corner as "localhost:3302"
Another reason this can sometimes come up is due to a misconfiguration in your docker-compose (if you're using it) whereby the mysql container is not on the same network that your app servers are on.
If the network flag is forgotten or incorrect docker won't add the mysql to the DNS for the app server and therefore throw an error like this.
We're using symfony with doctrine and we are in the process of automating deployment. I got this error when I simply hadn't provided the correct db creds in parameters.yml (I was running doctrine:migrations:migrate)
This thread has sent me on a bit of a wild goose chase, so I'm leaving this here so others might not have to.
Just as on FYI to others suddenly experiencing this on an otherwise (previously) working Laravel installation:
My Laravel environment is on a Ubuntu VirtualBox hosted on a Win-10 laptop.
I used my phone to share Internet via USB and suddenly started experiencing this issue. I changed to using the phone as wireless hotspot and the issue went away. This is a nameserver/networking issue and is not specific to Laravel or MySQL.
If someone facing this problem when using Docker
, be sure if you are using your version of SQL.
In my case: MYSQL_VERSION=latest
changing to MYSQL_VERSION=5.7
.
Then you need to remove your unused Docker images with docker system prune -a
(docs).
Also, in your .env
you need to change DB_HOST=mysql
. And run php artisan config:clear
.
I think it will help someone.
I'm using Laravel with Docker. I solved this problem by changing the value of DB_HOST
from localhost
to mysql
.
DB_HOST=mysql