Apache Commands You Should Know
3 min read
Apache HTTP server is the most popular web server in the world. It is a free, open-source, and cross-platform HTTP server providing powerful features that can be extended with a wide variety of modules.
If you are a developer or system administrator, chances are that you’re dealing with Apache regularly.
This guide will review the most important and frequently used Apache commands, including starting, stopping, and restarting Apache.
Before You Begin
In Ubuntu and Debian, the Apache service is named
apache2, while in Red-Hat based systems such as CentOS, the name of the Apache service is
If you are running CentOS, just replace
httpd in the commands below.
Starting Apache is pretty simple. Just type the following command.
sudo systemctl start apache2
On success, the command doesn’t produce any output.
If you are running an older Linux distribution without systemd to start Apache, type:
sudo service apache2 start
Instead of manually starting the Apache service, it is a good idea to set it to start on system boot:
sudo systemctl enable apache2
Stopping Apache shuts down the main Apache process and all child processes, even if there are open connections.
To stop Apache, run one of the following commands:
sudo systemctl stop apache2
sudo service apache2 stop
The restart option is a quick way of stopping and then starting the Apache server.
Use one of the following commands to perform a restart:
sudo systemctl restart apache2
sudo service apache2 restart
This is the command that you will probably use the most frequently.
You need to reload or restart Apache whenever you make changes to its configuration.
On reload, the main Apache process shuts down the child processes, loads the new configuration, and starts new child processes.
To reload Apache, use one of the following commands:
sudo systemctl reload apache2
sudo service apache2 reload
Test Apache Configuration
Whenever you make changes to the Apache server’s configuration file, it is a good idea to test the configuration before restarting or reloading the service.
Use the following command to test the Apache configuration for any syntax or system errors:
sudo apachectl -t
The output will look like this:
If there are any errors, the command prints a detailed message.
View Apache Status
To check the status of the Apache service, use the following command:
sudo systemctl status apache2
The output will look something like below:
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset:
Active: active (running) since Wed 2019-05-29 21:16:55 UTC; 6s ago
Process: 938 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
Process: 956 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCES
Main PID: 997 (apache2)
Tasks: 55 (limit: 1152)
├─ 997 /usr/sbin/apache2 -k start
├─ 999 /usr/sbin/apache2 -k start
└─1000 /usr/sbin/apache2 -k start
Check Apache Version
Sometimes, you may need to know the version of your Apache so you can debug an issue or determine whether a certain feature is available.
You can check your Apache version by running:
sudo apache2 -v
Server version: Apache/2.4.29 (Ubuntu)
Server built: 2019-04-03T13:22:37
-V (uppercase) option shows the Apache version along with the configure option.
sudo apache2 -V
In this guide, we have shown you some of the most essential Apache commands. If you want to learn more about the Apache command line, visit the Apache documentation
If you have any questions or feedback, feel free to comment.