Open In App

Most Useful Commands to Manage Apache Web Server in Linux

Last Updated : 24 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite: How do Web Servers work?

Apache is one of the most widely used free, open-source Web Server applications in the world, mostly used in Unix-like operating systems but can also be used in windows. As a developer or system administrator, it will be very helpful for you to know about the Apache webserver. It has many notable features among which  Virtual hosting is one such notable feature that allows a single Apache Web Server to serve a different number of websites.

We will discuss some of the most useful commands to manage Apache webserver (also called httpd on some other Linux-based distros) in Linux that you should know as a developer or system administrator. The commands that are going to be discussed must be executed as a root or sudo user.
 

Useful Commands to Manage Apache Web Server in Linux

Install Apache Server:

Installing Apache server on Debian/Ubuntu Linux using the following command:

sudo apt install apache2 
Useful Commands to Manage Apache Web Server in Linux

apache 2 already installed on my system

Check Apache Version:

For checking the installed version of the Apache webserver on the Linux system, use the following command:

 sudo apache2 -v
Useful Commands to Manage Apache Web Server in Linux

apache2 version

Display Apache compile settings:

To find about the Apache compile settings use the following command:

apache2 -V

Useful Commands to Manage Apache Web Server in Linux

Finding Syntax Errors in Apache Configuration File:

 For checking Apache configuration files for finding any syntax errors on Debian-based systems before restarting the service use the following command:-

 sudo apache2ctl -t
Useful Commands to Manage Apache Web Server in Linux

Syntax is Ok

Finding Errors in Apache Virtual Host:

Errors in Apache virtual host can be found out by using the following command below:-

apache2ctl -S

Useful Commands to Manage Apache Web Server in Linux

All the virtual hosts on the server, their options, and the file names and line numbers that they define, an error message with the line number are displayed that is very useful for troubleshooting the configuration file.

 Using Apache2 Service Commands

All the commands that will be discussed are applicable for Debian and Ubuntu Linux.

Start Apache Service:

For starting the Apache service, run the following command:

sudo service apache2 start

Restart Apache Service:

For restarting the Apache service, run the following command:

 sudo systemctl restart apache2

View Apache Service Status:

For viewing the Apache service, run the following command:

sudo systemctl status apache2 
Useful Commands to Manage Apache Web Server in Linux

status is active

Reload Apache Service:

For reloading(if you have made any changes in the configuration file then you can use this )the Apache service, run the following command:

sudo systemctl reload apache2

Restart the Apache Service:

For reloading the Apache service, run the following command:- 

systemctl restart apache2 

Stop Apache Service:

For stopping the Apache service, run the following command:- 

sudo systemctl stop apache2   

Show Apache Command Help:

For getting help with the Apache service commands by running the following command:- 

sudo apache2 -h  

Useful Commands to Manage Apache Web Server in Linux


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads