Most Useful Commands to Manage Apache Web Server in Linux - GeeksforGeeks

24 Feb, 2021
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. 
Install Apache Server:
Installing Apache server on Debian/Ubuntu Linux using the following command:
sudo apt install apache2 
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
apache2 version
Display Apache compile settings:
To find about the Apache compile settings use the following command:
apache2 -V
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
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
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.
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 
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  
linux-command
Picked
Technical Scripter 2020
Linux-Unix
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
scp command in Linux with Examples
mv command in Linux with examples
Docker - COPY Instruction
SED command in Linux | Set 2
chown command in Linux with Examples
nohup Command in Linux with Examples
Named Pipe or FIFO with example C program
Thread functions in C/C++
uniq Command in LINUX with examples
Start/Stop/Restart Services Using Systemctl in Linux