How to Stop, Start and Restart Apache Service

Restart Apache Service

One thing you will eventually need to know as you crawl through web servers is how to stop, start and restart Apache service.

The reason you will need to do this is usually Apache requires a restart when there is a change in configuration for the changes to take effect.

There is a slight problem. Apache is a cross-platform web server. Not only do these servers have different names, but the installation locations vary, there are different scripts used to manage the server depending on the distro.

Read Also  React 17.0 Release Candidate With No New Features

Seeing that different platforms might use different binary or script names it might be good to get that out of the way.

Generally, Debian, Ubuntu, and their variants use apache2 as the binary name. All other major Linux and Unix distros like openSUSE, SLES, Fedora Core, CentOS, RHEL, and macOS use httpd. Windows uses httpd.exe.

Stop, Start and Restart Apache Service Using httpd

Method 1: System V. Init scripts

/etc/init.d/httpd/[start|restart|stop|status]

On Ubuntu or Debian…

/etc/init.d/apache2/[start|restart|stop|status]

Method 2: Systemd

systemctl [start|restart|stop|status] httpd

On Ubuntu or Debian…

systemctl [start|restart|stop|status] apache2

Method 3: service command

service httpd [start|restart|stop|status]

On Ubuntu or Debian…

service apache2 [start|restart|stop|status]

Method 4: Apache binary script

apachectl [start|restart|stop|status]

or

apache2ctl [start|restart|stop|status]

Where the user is not root which is most of the time, you will need to prepend sudo to the above commands.