2
votes

Trying to run localhost to test a website in mac osx terminal.

andys-mbp:test Andy$ cd /Users/Andy/Desktop/test 
andys-mbp:test Andy$ php -S localhost:8000

This would usually work, but now I'm getting this error message:

Warning: Unknown: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in Unknown on line 0
[Tue Feb 24 12:55:58 2015] Failed to listen on localhost:8000 (reason: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known)

I've followed this tutorial to make sure PHP and apache are running, but it didn't seem to help...

How can I fix this? Any help very much appreciated!

2
What does it say if you change localhost to 127.0.0.1 - Robin Rijkeboer
Is localhost even known? Try to ping localhost and see if it returns a result. If not, you must bind localhost to ip 127.0.0.1 - Benz
ping: cannot resolve localhost: Unknown host - Andy W
I get the same error with 127.0.0.1 - Andy W
Do you also get the error with the IPv6 localhost ip address? e.g. php -S [::1]:8000 - justAnotherUser

2 Answers

8
votes

i think this guy has the same problem of you.. http://goo.gl/LQ0RgM

maybe you just need update your /etc/hosts, like commented on link:

The problem was with the host file. Fixed it by adding this to the /etc/hosts file:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
127.0.1.1 <hostname>

0
votes

Used ls -la on the /etc folder, and found the permissions were a bit strange on the hosts file... Restarted and all fine now... Thanks everyone for your help... very strange.