Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

localhost

When I type

"http://localhost"

in Safari I get an error saying that

"Safari can’t connect to the server."

when I should be getting a message saying

"it works!"

However when I ping "localhost" I get this result

Ping has started



PING localhost (127.0.0.1): 56 data bytes

64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.087 ms

64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.078 ms

64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.129 ms

64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.113 ms

64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.068 ms


--- localhost ping statistics ---

5 packets transmitted, 5 packets received, 0.0% packet loss

round-trip min/avg/max/stddev = 0.068/0.095/0.129/0.023 ms


which I understand to mean that it is working correctly. How can i resolve this issue as it means programmes like Timbuktu aren't recogonzing this computers DNS. Any ideas anyone ?

Posted on Jul 4, 2011 6:00 AM

Reply
21 replies

Jul 4, 2011 6:34 AM in response to Geoffrey Dyson

There seems to be some conflation of DNS translations and ping and Apache web services here.


Your use of ping shows that the name is translating correctly, which in aggregate means that local DNS and local IP are working.


That the http request is failing implies an issue here with the local web server, whether it is simply not launched, or it's failed or (if this is Mac OS X Server) the firewall is blocking port 80.


If this is Mac OS X client, then use System Preferences and start web services. (And look to use the user's Sites folder, as Mac OS X client runs Apache per-user by default.) If you're running Mac OS X Server, use the Server Admin tool to start the web server. If you're using MAMP or XAMPP or such, then ensure that that web server is running.


If you think the web server is running, then check the Console.app console log for related errors, and specifically have a look at the web server log files. On Mac OS X client 10.6 (Snow Leopard) and Mac OS X Server 10.6 (Snow Leopard Server), these Apache log files are stored in /var/log/apache2 directory.

Jul 4, 2011 6:58 AM in response to MrHoffman

Thanks for your rapid reply. I am using Mac OS client so I imagine that web services are not running. However in System Preferences there isn't any "start web services" function. Can you be more precise about how to turn them on ? There are no current errors mentioned in the /var/log/apache2 directory. I know that port 80 is open on my network, but is there some chance that it could be closed on this computer ? If it is, how do you open it ?

Jul 4, 2011 10:37 AM in response to etresoft

Either that, or he thinks he's tried to set up a web page and goofed it up. I'd expect a 404 error rather than a 'can't connect to server', but depending on what he's done he might be trying to connect somewhere that apache is set up to deny.


Honestly, he just hasn't provided enough information about what he's done and what he's doing. even a poor question for him to answer is better than us guessing wildly...

Jul 5, 2011 2:34 AM in response to MrHoffman

Thanks very much for that. However I think I need a little bit of hand holding here. From what I can tell from this

User uploaded file

PHP is enabled on my machine. If this is not the case, could you give me step by step instructions for the commands in Terminal as I can execute things in Terminal but I am not a geek.


Just to clear up the discussion above, here is the message I get when I type "localhost" in Safari

User uploaded file

And this is what I get on my other client machines.


User uploaded file

I realize that that is not the default Mac page, but I have forgotten why I ever changed it. But that is of little importance here. Thanks once again.

Jul 5, 2011 5:59 AM in response to Geoffrey Dyson

I'm going to show some Terminal.app commands here, and in italics.


It appears that Apache is not running on this host. This usually means that Apache web services have not been started on the host, or that there was an error when starting the web services.


As for how to set up php, please follow these instructions, as was mentioned earlier. (If you do not understand some of the steps, please post specific questions. Posting images won't help there, either. That's a fairly involved configuration file, and syntax errors can be introduced anywhere within it.)


If you've made changes to that php.ini file, then consider using a copy command (don't use a rename or a move command!) to copy the template file to replace the file that has been modified, or (if the default template file is missing) acquire a copy from your backups or from another Mac, and start over again. The command to copy the template to php.ini is sudo cp /etc/php.ini.default /etc/php.ini and then re-apply the changes from the instructions.


Then reboot.


Then ensure that the web sharing option is enabled via System Preferences.


Then test your connection using Safari. (Safari stinks as a test tool, but it's what you are familiar with.)


If that Safari connection fails, then check both your Safari access and error logs in /var/log/apache2 directory.

To verify that Apache is running, launch Terminal.app and issue the command sudo lsof -i -P | grep -i "http"

and (if Apache is running) you should see some techno-babble with "httpd" toward the left and TCP and *:80 and CLOSED and LISTEN toward the right; Apache processes that are listening on port 80. If you don't see a selection of output from the command, Apache is not running.


The Apache default directory for Mac OS X and Mac OS X Server is /Library/WebServer/Documents and that's where the "It works!" document resides in an index file. You can view the contents of this file with the command: cat /Library/WebServer/Documents/index.html.en

Jul 5, 2011 7:25 AM in response to Geoffrey Dyson

Geoffrey Dyson wrote:


I realize that that is not the default Mac page, but I have forgotten why I ever changed it. But that is of little importance here.

I think it is very important. You are starting to work on step 3 and you haven't completed step 1 yet.


When you go to http://localhost/~gdyson/, you should get the MacOS X site that says:

Your website

If you go to the root http://localhost/, you should get:

It works!


Don't go any further until both of those work. They should work as soon as you turn on Web Sharing. Worry about PHP later. That is not required yet.

Jul 5, 2011 7:24 AM in response to Geoffrey Dyson

just as an aside, unless you like using command-line text editors for some bizarre reason, you'll find it much easier to edit files like php.ini (or other config files) using TextWrangler. Some of the old-school unix guys forget (or don't care) that there are GUI programmer's text editors that make life much simpler.


Also - as someone who has been helping people with computer problems for a loooong time - whenever I hear someone say something like "I realize that that is not the default Mac page, but I have forgotten why I ever changed it. But that is of little importance here", I roll my eyes. Let me make two points perfectly clear, just so you have an easier time with forums like this in the future:


  • If you have a problem you cannot diagnose on your own, you are not in a position to determine what is and is not important.
  • If someone who's trying to help you in good faith asks you a question, answer it. Best case scenario is that you waste a couple of minutes answering a question that's of no relevance and build some good will; worst case, you cost yourself days of discussion and dozens of posts because you've neglected to provide some piece of information that turns out to be important, and everyone (including yourself) thinks you're a bonehead.


Up to you, of course. 😐

Jul 5, 2011 8:53 AM in response to twtwtw

twtwtw wrote:


just as an aside, unless you like using command-line text editors for some bizarre reason, you'll find it much easier to edit files like php.ini (or other config files) using TextWrangler. Some of the old-school unix guys forget (or don't care) that there are GUI programmer's text editors that make life much simpler.


Also - as someone who has been helping people with computer problems for a loooong time - whenever I hear someone say something like "I realize that that is not the default Mac page, but I have forgotten why I ever changed it. But that is of little importance here", I roll my eyes. Let me make two points perfectly clear, just so you have an easier time with forums like this in the future:


  • If you have a problem you cannot diagnose on your own, you are not in a position to determine what is and is not important.
  • If someone who's trying to help you in good faith asks you a question, answer it. Best case scenario is that you waste a couple of minutes answering a question that's of no relevance and build some good will; worst case, you cost yourself days of discussion and dozens of posts because you've neglected to provide some piece of information that turns out to be important, and everyone (including yourself) thinks you're a bonehead.


Up to you, of course. 😐


Point taken and fully appreciated. Thanks for the reminder.




As I understand it, Step 1 is the command "cd /etc"


when I give this command only "Mac-Pro:~ geoffreydyson$ " is returned


Step 2 is "sudo cp php.ini.default php.ini", When I give this command, I am asked to enter my password, after which "Mac-Pro:~ geoffreydyson$ " is returned


Am I to understand that these two commands should have given results other than those I just mentioned?


After having given those two commands "http://localhost/" and "http://localhost/~gdyson/" still give me the "Safari can't connect to the server" message even though "Web Sharing" is enabled in System Preferences.


The command "sudo lsof -i -P | grep -i "http" in Terminal asks me to enter my password, after which "Mac-Pro:~ geoffreydyson$ " is returned.



If that Safari connection fails, then check both your Safari access and error logs in /var/log/apache2 directory.


I don't know what you mean by "check both your Safari access" unless it is the attempts to connect to localhost. I was not able to check the log. I don't remember how you acces a path such as /var/log/apache2 directory


So the first question is, have I been doing everything correctly? If not what ?

And secondly where do I go from here ?

And lastly where is the default php.ini document meant to reside, as I can't find it ?

Jul 5, 2011 9:10 AM in response to Geoffrey Dyson

cd /etc should return Mac-Pro:etc geoffreydyson$ - the tilde you get implies you're still in your home folder. try ls to make sure that you're in the correct place before you run the cp command (again, this is a place where TextWrangler would make your life much easier). Is this an admin account or a normal user account, and if the latter is it in the sudoers file?


the point of the cp command is to replace/create the php.ini file from the default file provided for that purpose. the lsof command is trying to tell you whether your web server is up and running, and if it's not producing any results, it isn't. try running apachectl configtest.


and answer the question I asked earlier, otherwise I'm not wasting any more time here.

localhost

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.