The Apache service can be controlled using its provided binaries. Various distributions may refer to this binary by different names. For example, Ubuntu names it as apache2, while Red Hat uses httpd. This distinction can sometimes lead to confusion. The binary allows users to start, restart, and stop the service among other functionalities.

Historically, Linux and other Unix-based operating systems employed scripts and tools for service management. System V Init scripts were particularly popular but have been largely superseded by systemd in recent distributions. Nevertheless, other tools and scripts exist, though they're less commonly used.

In platforms that adopt systemd, System V Init scripts remain available for compatibility purposes. Additionally, Red Hat-based Linux distributions provide a service command offering similar functionalities.

MethodCommand
System V. Init scripts /etc/init.d/httpd [start|restart|stop|status]
Systemd systemctl [start|restart|reload|stop|status] httpd
service command service httpd [start|restart|stop|status]
Apache binary apachectl [start|restart|stop|status]

Different platform might use different binary/script names such as apache, apache2, apachectl or apache2ctl instead of httpd in the above example.
Related: Apache binary name for different distribution

Steps to start, restart, reload and stop Apache service from command line:

  1. Stop Apache service using Apache binary.
    $ sudo apache2ctl stop
    AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
  2. Start Apache service using System V. Init scripts.
    $ sudo /etc/init.d/apache2 start
    [ ok ] Starting apache2 (via systemctl): apache2.service.
  3. Restart the Apache service using systemd.
    $ sudo systemctl restart apache2
  4. Reload Apache configuration without stopping the service using systemd.
    $ sudo systemctl reload apache2
  5. Check the Apache service status using systemd.
    $ sudo systemctl status apache2
    ● apache2.service - The Apache HTTP Server
       Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset:
       Active: active (running) since Mon 2020-01-06 05:26:10 UTC; 14s ago
         Docs: https://httpd.apache.org/docs/2.4/
      Process: 1846 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCE
     Main PID: 1874 (apache2)
        Tasks: 55 (limit: 4591)
       Memory: 5.7M
       CGroup: /system.slice/apache2.service
               ├─1874 /usr/sbin/apache2 -k start
               ├─1875 /usr/sbin/apache2 -k start
               └─1876 /usr/sbin/apache2 -k start
    
    Jan 06 05:26:10 host systemd[1]: Starting The Apache HTTP Server...
    Jan 06 05:26:10 host apachectl[1846]: AH00558: apache2: Could not reliably deter
    Jan 06 05:26:10 host systemd[1]: Started The Apache HTTP Server.
  6. Disable Apache from starting on boot using systemd.
    $ sudo systemctl disable apache2
    Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
    Executing: /lib/systemd/systemd-sysv-install disable apache2
    Removed /etc/systemd/system/multi-user.target.wants/apache2.service.
  7. Enable Apache to start on boot using systemd.
    $ sudo systemctl enable apache2
    Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
    Executing: /lib/systemd/systemd-sysv-install enable apache2
    Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Discuss the article:

Comment anonymously. Login not required.