How to check if Apache2 is running from BASH command line

Sometimes, one wants to check if Apache2 is running. This is one way how to do it in BASH:

if [ "$(systemctl is-active apache2)" = "active" ]; then
  echo "Apache2 is active"
  ApacheIsRunning=1
else
  echo "Apache2 is not active"
  ApacheIsRunning=0
fi


(Last update on September 1, 2026 was done by Editor F.)

Leave a Reply

Your email address will not be published. Required fields are marked *