IlikedCPlusPlus
IlikedCPlusPlus

Reputation: 57

Webserver not listening to ports

Problem

I've recently found out that PHP has a built-in webserver which can be used for development purposes. Starting the server with the address "127.0.0.1" and the port "8080" works without any problems and my requests are handled properly. However, if I dare to use the address "localhost" with the same port, the webserver doesn't handle any requests.

Specs

  1. Windows 10 64-Bit
  2. Php 64-Bit Thread-Safe installed
  3. MongoDB installed (Not running)
  4. IIS Server installed and running
  5. MariaDB installed (Not running)

Upvotes: 1

Views: 498

Answers (1)

AbraCadaver
AbraCadaver

Reputation: 78994

Name resolution for localhost is handled by your DNS server which is likely resolving it to the IPv6 address ::1.

If you run:

php -S 127.0.0.1:8080

The webserver is running on the IPv4 address but localhost resolves to the IPv6 address.

So you can either use 127.0.0.1:8080 in the browser address bar.

Or force the address by un-commenting the following line from C:\Windows\System32\drivers\etc\hosts:

#   127.0.0.1       localhost

Or bind the webserver to the IPv6 address (this is what I do):

php -S localhost:8080

Upvotes: 1

Related Questions