Oct 19, 2023 3 min read

Apache Commands You Should Know

Learn about Apache Commands you should know with our step-by-step tutorial. Apache Commands are the most widely used web server worldwide.

 Apache Commands You Should Know
Table of Contents


Before we start talking about the Apache Commands you should know, let's briefly understand-What is Apache ?

The Apache HTTP server is the most widely used web server worldwide. It is a cross-platform, free, open-source HTTP server with robust functionality that may be enhanced with a range of modules.

If you're a programmer or a system administrator, you're probably familiar with Apache.

We'll go over the most critical and commonly used Apache commands, such as starting, halting, and restarting Apache, in this tutorial. We will also address a few FAQs on Apache Commands.

Before You Begin

We'll assume you're logged in as root or as a user with sudo access. Any contemporary Linux distribution, such as Ubuntu 18.04, CentOS 7, or Debian 9, should work with the commands in this article.

The Apache service is known as apache2 in Ubuntu and Debian, whereas it is known as httpd in Red Hat-based systems such as CentOS.

Simply replace apache2 with httpd in the commands below if you're using CentOS.

Start Apache

It's easy to get Apache up and running. Simply input the command below.

sudo systemctl start apache2

The command does not provide any output if it succeeds.

If you're using an earlier Linux distribution that doesn't have systemd, type:

sudo service apache2 start

It's a good idea to set the Apache service to start automatically instead of manually starting it:

sudo systemctl enable apache2

Stop Apache

Even if there are open connections, stopping Apache rapidly shuts down the main Apache process and all child processes.

Run one of the following commands to stop Apache:

sudo systemctl stop apache2
sudo service apache2 stop

Restart Apache

The restart option allows you to quickly stop and start the Apache server.

To restart, type one of the following commands:

sudo systemctl restart apache2
sudo service apache2 restart

This is the command that you will almost certainly use the most.

Reload Apache

When you make changes to Apache's settings, you must reload or restart it.

The main Apache process shuts down the child processes, loads the new configuration, and starts new child processes when the configuration is reloaded.

Use one of the following commands to reload Apache:

sudo systemctl reload apache2
sudo service apache2 reload

Test Apache Configuration

It's a good idea to test the configuration before restarting or reloading the Apache server whenever you make changes to the configuration file.

To check for any syntactic or system issues in the Apache configuration, run the following command:

sudo apachectl -t

You will get an output like below:


Syntax OK

The command provides a descriptive message if there are any errors.

View Apache Status

Use the following command to verify the status of the Apache service:

sudo systemctl status apache2

You will get an output like below:


● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: 
  Drop-In: /lib/systemd/system/apache2.service.d
   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)
   CGroup: /system.slice/apache2.service
           ├─ 997 /usr/sbin/apache2 -k start
           ├─ 999 /usr/sbin/apache2 -k start
           └─1000 /usr/sbin/apache2 -k start

Check Apache Version

You may need to know the Apache version to troubleshoot an issue or determine whether a feature is available.

You can find out what version of Apache you're running by typing:

sudo apache2 -v

Server version: Apache/2.4.29 (Ubuntu)
Server built:   2019-04-03T13:22:37

Along with the configure option, the -V (uppercase) option displays the Apache version.

sudo apache2 -V

FAQs on Apache Commands you should know

How can I check the status of Apache? 

Run the command: sudo systemctl status apache2

Where are the Apache configuration files located? 

Apache configuration files are typically found in the /etc/apache2/ directory on Ubuntu and Debian systems.

How do I test the Apache configuration for syntax errors? 

Use the command: sudo apachectl configtest

How can I reload the Apache configuration without restarting the server? 

Run the command: sudo systemctl reload apache2

How can I view the Apache access log? 

Use the command: sudo tail -f /var/log/apache2/access.log

How do I change the Apache server's default port? 

Edit the ports.conf file within the Apache configuration directory. Change the Listen directive to the desired port, and restart Apache for the changes to take effect.

How can I test Apache's response to a request? 

Use the curl command to send an HTTP request to your server. For example: curl -I localhost to check the server response headers.


We've covered some of the most important Apache commands in this article. Visit the Apache documentation to learn more about the Apache command line.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.