Restarting Apache on Gentoo

Normally, you can restart Apache using the restart command for the init.d script.

/etc/init.d/apache2 restart

However, you may encounter the following error.

chris@server /root $ sudo /etc/init.d/apache2 restart
 * Stopping apache2 ...[ ok ]
 * Starting apache2 ...
 * start-stop-daemon: /usr/sbin/apache2 is already running 

This is due to a bug in the init.d script. You can resolve this with a one line change.

vim /etc/init.d/apache2

Change line 105 for the one below (they should look very similar).

while ( test -f "${PIDFILE}" && pgrep -P ${PID} apache2 >/dev/null ) \

Save it and run the restart command again to check it has worked.

chris@server /root $ sudo /etc/init.d/apache2 restart
 * Caching service dependencies ...                                                                              [ ok ]
 * Stopping apache2 ...                                                                                          [ ok ]
 * Starting apache2 ...

If you get an output like the above, you’ll know it’s worked.