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
Check Apache Version:
For checking the installed version of the Apache webserver on the Linux system, use the following command:
sudo apache2 -v
Display Apache compile settings:
To find about the Apache compile settings use the following command:
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
Finding Errors in Apache Virtual Host:
Errors in Apache virtual host can be found out by using the following command below:-
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
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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.