Skip to content
Advertisement

php -S randomly not working: localhost refused to connect [closed]

I am using WSL2 with ubuntu 20.04 with php 7.4.3 installed on it. Sometimes, php -S (for example php -S localhost:9000 -t public) doesnt work, nor does php artisan serve.

EDIT: When trying to access the address localhost:9000 from the browser, i get: “localhost refused to connect” terminating WSL distro has never solved the issue. From the terminal i get the normal: PHP 7.4.3 Development Server (http://127.0.0.1:9000) started

Advertisement

Answer

Answering my own question.

This seems to be a common issue on WSL2, and a fix is coming. In the meantime,

  • wsl –shutdown may solve the issue.

  • if that is indeed the case, you can get the correct localhost address by using the command below.

ip addr | grep -E "binet.global" | sed -E "s/inet(.)/./1/“

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement