Home  »  GuidesProgrammingResourcesSoftwareTechnology   »   How to Stop, Start and Restart Apache Service

How to Stop, Start and Restart Apache Service

One thing you will eventually need to know as you crawl through web servers is how to stop, start and restart the 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.

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

$ sudo /etc/init.d/httpd/restart
$ sudo /etc/init.d/httpd/start
$ sudo /etc/init.d/httpd/stop
$ sudo /etc/init.d/httpd/status

On Ubuntu or Debian…

$ sudo /etc/init.d/apache2/restart
$ sudo /etc/init.d/apache2/start
$ sudo /etc/init.d/apache2/stop
$ sudo /etc/init.d/apache2/status

Method 2: Systemd

$ sudo systemctl restart httpd
$ sudo systemctl start httpd
$ sudo systemctl stop httpd
$ sudo systemctl status httpd

On Ubuntu or Debian…

$ sudo systemctl restart apache2
$ sudo systemctl start apache2
$ sudo systemctl stop apache2
$ sudo systemctl status apache2

Method 3: service command

$ sudo service httpd restart
$ sudo service httpd start
$ sudo service httpd stop
$ sudo service httpd status

On Ubuntu or Debian…

$ sudo service apache2 restart
$ sudo service apache2 start
$ sudo service apache2 stop
$ sudo service apache2 status

Method 4: Apache binary script

$ sudo apachectl restart
$ sudo apachectl start
$ sudo apachectl stop
$ sudo apachectl status

or

$ sudo apache2ctl restart
$ sudo apache2ctl start
$ sudo apache2ctl stop
$ sudo apache2ctl status

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

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.