Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Polecalex's avatar

No such host is known

Hello,

I am trying to test my account system on my laravel project, I have input the correct mysql details such as the correct host, db, password and user however any attempt i make to connect to the database and run a query, it just returns "SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known."

The database is on my school's server which i have full access to my account, so i am able to read and write to it, I have already connected to it before to run the migrations which created the "users" and "posts" tables and they were successful. I am unsure what is going wrong as if it had already connected then why would it return "No such host is known".

Here is my env file snippit:

DB_CONNECTION=mysql
DB_HOST=https://hidden.link.net
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=user.name
DB_PASSWORD=PASSWORD
0 likes
13 replies
musa11971's avatar

Please read this thread. It may be relevant to your question.

If that's not it, you can try clearing your cache: php artisan config:clear

Polecalex's avatar

@MUSA11971 - Thanks for the quick reply, unfortunately, I have tried both of these and still no success, I have tried adding quotation marks around the password, the username, and the host but still no luck.

I just don't understand that I was able to connect with the same details to migrate the database, but not create data

Polecalex's avatar

I have just noticed, I have tried to change the .env multiple times, trying it on my local database server, tried to migrate my tables but it was telling me that I was still trying to connect to the external server, not the local database.

I have tried to clear the cache and config, turned off my computer and tried doing multiple things, but still no luck, i don't think it is using my .env file as i have also tried resetting my app_key and nothing changes within the .env but no luck. Not sure what is going on as i can't get anything to work. If anyone knows why the .env file isn't working as expected please explain.

jlrdw's avatar

Can you connect with something like phpmyadmin eith the exact same credentials as above.

And have you checked to make sure you don't have two occurrences of MySQL and you are trying to connect to wrong one.

Snapey's avatar

Why would your server have a https:// address ? You need its IP address.

Polecalex's avatar

@JLRDW - I am able to connect and edit the tables using the exact details and there is only 1 instance of MySQL running so I am connecting to the correct one.

Polecalex's avatar

@SNAPEY - I have changed this, however still no luck. If you read my reply above, I have explained that for some reason, my app isn't looking at the .env and it is continuing to look at the cached .env file. However, I have cleared the cache to reset this but it continues to use a cached version of .env from somewhere

Snapey's avatar

To check if cached config is correct, you can open tinker and type config('database.connections.mysql')

siangboon's avatar

have you try to ping the exact host and telnet the exact host with the port?? And do check the error log for more details sometime it may help. telescope is one of the great debugging tool that you can try.

aiMeta's avatar

Also had this issue -- after doing a few online tuts and various exercise - in one of the tuts they suggested changing the sql ip to localhost -- all worked well except when trying to register a user... changed it back, cleared cache and all went back to normal.

KingStevenNOS's avatar

The solution is simple really. Just comment out the DB_HOST section in your .env file. It's throwing this error because it doesn't recognize the host that you have declared as the DB_HOST.

2 likes

Please or to participate in this conversation.