/Tips on how to cease, begin, and restart Apache on varied Linux distributions

Tips on how to cease, begin, and restart Apache on varied Linux distributions


Need to know how to start, stop, restart, enable, and disable Apache? Here’s how.

How to stop, start, and restart Apache on various Linux distributions

Need to know how to start, stop, restart, enable, and disable Apache? Here’s how.

Your business depends on websites to drive customers. If your data center makes use of Linux, chances are your websites are powered by the Apache web server. That being the case, you might want to know how to control that service.

Of course, you might be thinking, “Isn’t Apache enabled and started upon installation?” Sure it is, and it will remain so, unless you take action. But there are times when you might need to stop, restart, and even disable the web server. That’s why you need to know how to control it.

However, you might also discover how this works depends on the distribution you use. Let’s find out how to take care of the stopping, starting, and restarting the Apache web server on Ubuntu/Debian (and their derivatives), CentOS/RHEL (and their derivatives), and non-systemd distributions.

SEE: Hiring kit: Database administrator (TechRepublic Premium)

What You’ll Need

The only things you’ll need for this are:

  • A running distribution with the Apache web server installed
  • A user account with sudo privileges

And thus, let’s get to work.

How to start, stop, and restart Apache on Ubuntu/Debian

We’ll first take care of this on one of the most widely-deployed server distributions on the planet. On Ubuntu the Apache service is apache2 and is controlled via systemd, with the systemctl command.

To start Apache, the command would be:

sudo systemctl start apache2

To stop Apache, the command would be:

sudo systemctl stop apache2

To restart the Apache server, issue the command:

sudo systemctl restart apache2

If you only change a configuration file, and need to reload that file, you can do so without completely restarting Apache with the command:

sudo systemctl reload apache2

In order to have Apache restart automatically at system boot, you must enable the service with the command:

sudo systemctl enable apache2

To disable the Apache service (and prevent it from starting at boot), issue the command:

sudo systemctl disable apache2

To get the status of the Apache service, issue the command:

sudo systemctl status apache2

The status command will give you quite a bit of information. What you want to look for is the active (running) listing (Figure A).

Figure A

apachestarta.jpg

How to start, stop, and restart Apache on CentOS/RHEL

Now we turn to the other favorite server platform—those based on Red Hat Enterprise Linux (RHEL). Unlike Ubuntu, which installs Apache as apache2, these flavors of Linux install the Apache service as httpd. On the plus side, both do make use of systemd and the systemctl command. Because of this, starting/stopping/enabling Apache is quite similar.

To start Apache, issue the command:

sudo systemctl start httpd

To stop the Apache server, issue the command:

sudo systemctl stop httpd

To restart the Apache server, issue the command:

sudo systemctl restart httpd

To reload the Apache configuration files, issue the command:

sudo systemctl reload httpd

To enable the Apache service, issue the command:

sudo systemctl enable httpd

To disable the Apache service, issue the command:

sudo systemctl disable httpd

How to start, stop, and restart Apache on non-systemd systems

What if your system doesn’t use systemd? You’re not out of luck. With the installation of Apache, comes the apachectl command. The stopping, starting, and restarting of Apache with this command is very similar to that above.

To start Apache, the command is:

sudo apachectl start

To stop Apache, the command is:

sudo apachectl stop

To restart Apache, the command is:

sudo apachectl restart

To get the status of the Apache service, issue the command:

sudo apachectl status

To reload configuration files, issue the command:

sudo apachectl reload

To enable Apache to start at boot, issue the command:

sudo apachectl enable

To disable the Apache service, issue the command:

sudo apachectl disable

And that, my friends, should cover you for stopping, starting, reloading, enabling, and disabling the Apache web server, regardless of your distribution. Although there might be a fringe distribution this doesn’t cover, you shouldn’t have any trouble controlling the web server on Linux.

Also see

apachehero.jpgapachehero.jpg
Original Source