Apache running but no response from server?

Solution 1:

Sounds like a firewall issue if wget works from the command line.

Temporarily disable the firewall using:

service iptables stop

If it works then you know you need to add a rule to your firewall to allow port 80 and or 443.

Solution 2:

On CentOS 7 or similar, check if you're running firewalld:

systemctl status firewalld

Ubuntu has ufw which is a friendlier interface to iptables. See man ufw for details.

If you see the service running, you can open port 80 by adding the http service as explained by root users:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload

Incidentally, I once installed CentOS 7 minimal on a machine and the firewall was not installed by default. But using another ISO on another machine, it was installed on its own. And I kept checking on the wrong one, which told me that there was no firewall!

A useful command that will tell you that it's definitely the firewall is nmap:

sudo nmap -sS -O -p80 ip-address

Starting Nmap 7.01 ( https://nmap.org ) at 2017-08-11 15:56 IST
Nmap scan report for ip-address
Host is up (0.0011s latency).
PORT   STATE SERVICE
80/tcp open  http

If you see filtered instead of open, there's no doubt a firewall. Double check you're in the right machine if you have several terminals open!

Another quick way to check from the terminal is to use curl. On the server:

curl localhost

That should return the homepage. On another machine on the network:

curl 1.2.3.4     # use the actual host's IP address

That should also return the homepage. If you have to press CTRL+C because it sits waiting, or if you get an error like Failed to connect to 1.2.3.4 port 80: No route to host but got a response when you did it locally, it's a clear sign that something, most likely a firewall, is blocking access.