ERROR: apache2 failed to start

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

Documentation

Stopping and Restarting Apache HTTP Server
https://httpd.apache.org/docs/2.4/stopping.html

Sample errors

AH01564: unable to find IPv4 address

sample error:

# service apache2 start
* Executing: /lib64/rc/sh/openrc-run.sh /lib64/rc/sh/openrc-run.sh /etc/init.d/apache2 start
* Starting apache2 ...
* Detaching to start `/usr/sbin/apache2' ...
*   start-stop-daemon: failed to start `/usr/sbin/apache2'            [ !! ]
* ERROR: apache2 failed to start

Checking the logs:
# tail /var/log/apache2/error_log
[Mon Oct 31 16:44:54.746186 2016] [unique_id:alert] [pid 20665] (EAI 2)Name or service not known: AH01564: unable to find IPv4 address of "gentoo-foobar"
AH00016: Configuration Failed

Solution: add the corresponding address in /etc/hosts:

# vi /etc/hosts
127.0.0.1       gentoo-foobar

httpd (pid nnnnn?) not running

The server has crashed:

# service apache2 status
* status: crashed

Starting it, stopping or restarting it does not help:
# service apache2 stop
* Caching service dependencies ...
[ ok ]
* Stopping apache2 ...
httpd (pid 10847?) not running         [ !! ]
* ERROR: apache2 failed to stop

# service apache2 start
* WARNING: apache2 has already been started

# service apache2 restart
* Stopping apache2 ...
httpd (pid 10847?) not running         [ !! ]
* ERROR: apache2 failed to stop
ks304960 /home/augustin # killall -9 apache2

Solution: remove the cached pid process:

# rm /var/run/apache2.pid

# service apache2 status
* status: crashed
# service apache2 start
* WARNING: apache2 has already been started
# service apache2 stop
* apache2 not running (no pid file)
# service apache2 start
* Starting apache2 ...       [ ok ]
# service apache2 status
* status: started