Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 787
ayobamilaye Avatar asked Oct 31 '19 15:10

ayobamilaye


2 Answers

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
like image 184
Salim Djerbouh Avatar answered Nov 05 '22 16:11

Salim Djerbouh


Your DB_HOST environment variable is clearly wrong. You added the http:// URI Scheme to it. The http:// scheme is for identifying a http protocol, MySQL don't use it.

You should use only the hostname, without prefixes:

DB_HOST=localhost
like image 3
Elias Soares Avatar answered Nov 05 '22 17:11

Elias Soares