[Fixed] message: "SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (SQL: select * from `users`…)"

Issue

I developed a Web Portal on Windows Operating System using Angular-7 as the frontend and Laravel-5.8 as the backend. Before deployment, I tested everything on the local machine and it was okay.

The Linux Ubuntu server IP is: 20.10.10.122
The Laravel file path is:

http://120.10.10.122/client-app/backend

.env

APP_NAME=Client
APP_ENV=local
APP_KEY=base64:QT/LLNA/aduSekOXF4/CsY1iYEcRwwwwssssssHxuFs=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=http://localhost/
DB_PORT=3306
DB_DATABASE=client
DB_USERNAME=jdggsss
DB_PASSWORD=kjhgfdddd

However, when I deployed to Linux Ubuntu-18 Server, I ran the application. When the user tried to login, I got this error:

message: “SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (SQL: select * from users where email = [email protected] and active = 1 and deleted_at is null and users.deleted_at is null limit 1)”

Why am I getting the error and how do I resolve it?

Solution

Change your environment variable to connect to the local MySQL server via TCP

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=client
DB_USERNAME=jdggsss
DB_PASSWORD=kjhgfdddd

Leave a Reply

(*) Required, Your email will not be published