How to start, stop and restart apache on Ubuntu?


Apache is a free and open-source cross-platform web server software. It is one of the most popular HTTP servers. It is generally used in combination with MySQL, PHP, and other scripting languages and forms a robust platform for the deployment of web applications. We already discussed how to install apache web server on Linux using the LAMP stack.

In this article, you will learn how to start, stop and restart the apache web server on Ubuntu and other Debian-based distributions.

Start, stop and restart the apache using systemctl

Most of the modern distributions today uses systemd as init system. On these systems, we can use the systemctl command to manage services.

Type the following command to start the apache2 web server on a system –

sudo systemctl start apache2

You can check the status, if the server is running or not by using –

sudo systemctl status apache2

If the server is running you will see the given output –

After making changes in the configuration file you often need to restart the server. You can use the following command to restart the apache server on your system –

sudo systemctl restart apache2

If you want to stop the Apache webserver service the execute the given command –

sudo systemctl stop apache2

Start, stop and restart the apache using the service command

Sysvinit is a traditional init system for Unix/Linux whose primary purpose is initializing, managing, and tracking system services and daemons. The older version of Ubuntu, Debian, and such other systems uses sysvinit. We can use the service command to manage services on these systems.

Use the following command to start the apache2 web server on a system –

sudo service apache2 start

You can check the status of a server that it is running or not by using –

sudo service apache2 status

Generally, you need to restart your server after making changes in the configuration file. You can use the following command to restart the apache server on your system –

sudo service apache2 restart

To stop the apahce2 services use the following command –

sudo service apache2 stop

Start, stop and restart the apache using /etc/init.d/apache2 command

By using /etc/init.d/apache2 command you can also manage the apache services. Now see the below commands –

To start the apache2 service execute the given command –

sudo /etc/init.d/apache2 start

To check apache2 server-status use –

sudo /etc/init.d/apache2 status

If you want to restart the apache2 service use  –

sudo /etc/init.d/apache2 restart

To stop the apache2 service execute the following command –

sudo /etc/init.d/apache2 stop

Conclusion

There are multiple ways in which you can start, stop or restart the apache2 service on a Linux system. Now if you have a query then write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.