how to make apache2 listen to localhost and a lan computer

Solution 1:

Check with netstat that apache is listening on port 80.

% sudo netstat -apn|grep :80
tcp        0      0 :::80                       :::*                        LISTEN      1318/httpd          

Also make sure that you do not have any firewall rules blocking this access, specifically you should have ACCEPT rules on the INPUT chain for http.

% sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:http 
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 

You can temporarily disable your firewall to confirm with this:

% /etc/init.d/iptables stop

So then the firewall looks like this:

% sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

I would also check out the Apache error and access logs files, most linuxes store these under /var/log, possibly /var/log/httpd. They're usually 2 files, error_log and access_log.

Regarding the error you're getting on startup, sounds like you need to set the ServerName variable in your httpd.conf file.

ServerName localhost

This seems to be an issue with apache2 on Ubuntu. I found several threads on other sites where the solution was to set ServerName to localhost.

  • How to fix Apache – "Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName" Error on Ubuntu
  • Apache2 bug?
  • [SOLVED] apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName on Xubuntu
  • [SOLVED] “Could not reliably determine the server’s fully qualified domain name, using … for ServerName”