Apache Commands You Should Know

Apache Commands You Should Know

In this guide, we will go over the most important and frequently used Apache commands, including starting, stopping, and restarting Apache.

If you are a developer or system administrator, chances are that you’re dealing with Apache regularly.

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 by a wide variety of modules.

 

Before You Begin

We’re assuming that you are logged in as root or user with sudo privileges. The commands in this guide should work on any modern Linux distribution like Ubuntu 18.04 and CentOS 7 and Debian 9 .

In Ubuntu and Debian, the Apache service is named apache2, while in Red Hat based system such as CentOS, the name of the Apache service is httpd.

If you are running CentOS, just replace apache2 with httpd in the commands below.

 

Start Apache

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

 

Stop Apache

Stopping Apache quickly shut 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

 

Restart Apache

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

This is the command that you will probably use the most frequently.

 

Reload Apache

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

 

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:

Syntax OK

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: 
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   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

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

The -V (uppercase) option shows the Apache version along with the configure option.

sudo apache2 -V

For more information you can check Apache documentation.

Remote DDoS Protection plans

Check out our Remote DDoS protection plans which are perfectly compatible with apache and nginx . 

See More