Questions & Answers

Apache/PHP - localhost stopped working. How do I get it to work again?

I have installed Apache2.2 on my computer, PHP 5, and MySQL. Everything was working fine until last night. Suddenly, I could no longer connect to the localhost. I think my computer was infected with a trojan, but that has since been removed and I am unable to reconnect to my localhost.

I have updated my hosts file Windows(C:)/Windows/System32/drivers/etc hosts in notepad: see attachment.

I have tested my connection in the CMD prompt see attachment.

You'll notice [::]1, but after updating my host file, it now displays as

Additionally, port 80 IS LISTENING

instead of my web browser loading the page as localhost/vote/home.php NOW it loads as file:///C:/Websites/Vote/home.php AND NOW my PHP no longer works i.e. not being pulled into my web page.

...can't establish a connection to the server at localhost.

Why is my local host not working? Thoughts? Thank you in advance.

Additionally, my web browser page does not time out when requesting localhost....

(I'm a new user so I am unable to post images)?

× 257296

Answers(4) :

if you put localhost/vote/home.php into your browser's address bar you should get an unabled to connect error, not a redirect to a file. The only time the address bar will show file:///C:/Websites/Vote/home.php is if you open that file directly in your browser.

Your details about why apache isnt working are not to clear, but you can try a couple of things. First, how did you install apache, is it a service? you can check this by going to control panel > Administrative Tools > Services and see if apache is in that list. If its, you have to start it, if its not then apache is not installed as a service and you need to start it by running the executable. Go to the whichever directory your httpd executable is and run it.

2023-01-20 23:01:14
Yes, it must have been because I opened the file manually. When I enter localhost/vote/home.php into the browser it does nothing, but attempt to load for many many minutes before (it is still trying to load and I am done typing this post). Apache is installed as a service; please keep in mind Apache was working fine and now is not. I have uninstalled and reinstalled it since.
2023-01-20 23:01:14
not all services start automatically, if it use to start automatically somehow it must of been disabled. did the reinstall work for you?
2023-01-20 23:01:14
I downloaded Apache from (Win32 Binary without crypto (no mod_ssl) (MSI Installer): httpd-2.2.22-win32-x86-no_ssl.msi [ PGP ] [ MD5 ] [ SHA1 ]) based on the site - , again, this was working.
2023-01-20 23:01:14
I see the Apache icon in the icon tray, the service is running. The reinstall did not work.
2023-01-20 23:01:14
have you tried localhost:8080 ... maybe you are running on another port
2023-01-20 23:01:14
BTW my page is still trying to load
2023-01-20 23:01:14
Firefox can't establish a connection to the server at localhost:8080.
2023-01-20 23:01:14
C:\Apache2.2\conf\httpd - # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # #Listen Listen 80

Some things to try:

  • Make sure Apache is actually running, that it haven't failed during startup.
  • Check if it's listening to the expected port (80, or whatever you have configured it to)

    > netstat -nb
  • Check your hosts file to make sure nothing fishy is going on there. localhost should point to, but maybe it's been set to point somewhere else by your virus thing.

If you can't figure it out, you can always try to remove/uninstall and try to set it up again. If this is a developer machine, I can recommend using the WAMP package installer instead of setting it all up yourself. It provides fairly easy switching between php/apache/mysql versions and easy switching on and off of most regular apache and php modules.

2023-01-20 23:01:14
I have reinstalled the software since the removal of the virus. Apache is running. httpd - Apache is set to listen to port 80. Host file - localhost. This was actually a pretty easy setup and was working for several weeks without an issue, I'm just not sure why it's not working now.
2023-01-20 23:01:14
Maybe time for a clean install of your OS then :)

run command prompt as administrator and go to Apache bin folder (usually 'cd \apache\bin' ) and type httpd -k start. it worked for me with the same issue.

I had the exact issue. If you have a XAMPP control panel pull it up. There you will see XAMPP Control Panel Image the different modules that you have open... Apache will be one of them. In the 'Actions' column you will have 'Stop' adjacent to it. Hit the 'Stop' and wait about 1 minute for everything to calm down. The button will change to 'start' so hit it. This will reset Apache. It worked for me...Good Luck. If you don't have the control panel on your desktop, go into your programs list and drop-down the XAMPP icon. The control panel is right there. Just click it and it will show