Linux apachectl Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the apachectl command to manage the Apache web server on a Linux system. You will understand the different options available with the apachectl command, and learn how to start, stop, and restart the Apache web server, as well as check its status. The lab covers the essential tasks for administering the Apache web server using the command-line interface.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") linux/SystemInformationandMonitoringGroup -.-> linux/ps("`Process Displaying`") linux/SystemInformationandMonitoringGroup -.-> linux/service("`Service Managing`") subgraph Lab Skills linux/sudo -.-> lab-422544{{"`Linux apachectl Command with Practical Examples`"}} linux/ps -.-> lab-422544{{"`Linux apachectl Command with Practical Examples`"}} linux/service -.-> lab-422544{{"`Linux apachectl Command with Practical Examples`"}} end

Understand the apachectl Command

In this step, we will learn about the apachectl command, which is a command-line tool used to control the Apache web server. The apachectl command provides a convenient way to start, stop, restart, and check the status of the Apache web server.

First, let's check the version of the Apache web server installed on our system:

sudo apachectl -v

Example output:

Server version: Apache/2.4.52 (Ubuntu)
Server built:   2022-06-08T12:06:22

The apachectl -v command displays the version of the Apache web server installed on the system.

Next, let's explore the different options available with the apachectl command:

sudo apachectl -h

Example output:

Usage: apachectl [option]
Options:
  start            Start the Apache httpd daemon
  stop             Stop the Apache httpd daemon
  restart          Restart the Apache httpd daemon
  graceful         Gracefully restart the Apache httpd daemon
  graceful-stop    Gracefully stop the Apache httpd daemon
  configtest       Run a configuration syntax test
  status           Display the status of the Apache httpd daemon
  fullstatus       Display a full status report from mod_status
  help             Display usage information
  -k start|stop|restart|graceful|graceful-stop  Perform operation
  -v               Print version and then exit
  -V               Print version and built-in modules, then exit
  -t               Run configuration syntax test
  -D name         Define a global variable
  -f file         Specify an alternate ServerRoot file

This output shows the various options available with the apachectl command, including starting, stopping, restarting, and checking the status of the Apache web server.

Start, Stop, and Restart the Apache Web Server

In this step, we will learn how to start, stop, and restart the Apache web server using the apachectl command.

First, let's start the Apache web server:

sudo apachectl start

Example output:

Starting Apache httpd web server: apache2.

The apachectl start command starts the Apache web server.

Next, let's stop the Apache web server:

sudo apachectl stop

Example output:

Stopping Apache httpd web server: apache2.

The apachectl stop command stops the Apache web server.

Finally, let's restart the Apache web server:

sudo apachectl restart

Example output:

Restarting Apache httpd web server: apache2.

The apachectl restart command restarts the Apache web server.

Check the Apache Web Server Status

In this step, we will learn how to check the status of the Apache web server using the apachectl command.

First, let's check the basic status of the Apache web server:

sudo apachectl status

Example output:

Apache Server Status for localhost (via 127.0.0.1)

Server Version: Apache/2.4.52 (Ubuntu)
Server Built:   2022-06-08T12:06:22

Current Time: Wednesday, 26-Apr-2023 19:14:22 UTC
Server uptime:   0 minutes 12 seconds
Total accesses: 0 - Total Traffic: 0 bytes
CPU Usage: u0.000 s0.000 cu0.000 cs0.000 - 0.00% CPU load
1 requests/second - 0 B/second - 0 B/request
0 requests currently being processed, 2 idle workers

Scoreboard: _________________________________________________________________

The apachectl status command displays the basic status of the Apache web server, including the server version, uptime, and current activity.

To get more detailed status information, we can use the apachectl fullstatus command:

sudo apachectl fullstatus

Example output:

Apache Server Status for localhost (via 127.0.0.1)

Server Version: Apache/2.4.52 (Ubuntu)
Server Built:   2022-06-08T12:06:22

Current Time: Wednesday, 26-Apr-2023 19:15:01 UTC
Restart Time: Wednesday, 26-Apr-2023 19:14:10 UTC
Parent Server Generation: 0
Server uptime:   0 minutes 51 seconds
Total accesses: 0 - Total Traffic: 0 bytes
CPU Usage: u0.000 s0.000 cu0.000 cs0.000 - 0.00% CPU load
1 requests/second - 0 B/second - 0 B/request
0 requests currently being processed, 2 idle workers

Scoreboard: _________________________________________________________________

Srv PID Acc M CPU SS Req Conn Child Slot
--- --- --- - --- -- --- ---- ----- -----
0-0 - 0 _ 0.00 0 0 0 0 _
0-1 - 0 _ 0.00 0 0 0 0 _

The apachectl fullstatus command provides more detailed information about the Apache web server, including the number of requests, CPU usage, and worker status.

Summary

In this lab, we learned about the apachectl command, which is a command-line tool used to control the Apache web server. We explored the different options available with the apachectl command, including starting, stopping, restarting, and checking the status of the Apache web server. We then learned how to start, stop, and restart the Apache web server using the apachectl command, and how to check the status of the Apache web server.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like