LinuxCommandLibrary

apache2

Manage the Apache web server

SYNOPSIS

apache2 [-D] [-d directory] [-k command] [-C password] [-c configfile] [-v] [-V] [-h] [command]
command: start|stop|restart|reload|graceful|graceful-stop|status|configtest|fullstatus|foreground

PARAMETERS

-D
    Do not daemonise (run in foreground)

-d directory
    Chdir to directory before daemonising

-k command
    Run command: start|stop|restart|reload|graceful|graceful-stop|configtest|status|fullstatus|foreground

-C password
    Decode Base64 password for -k start

-c configfile
    Use alternate config file

-v
    Show version

-V
    Verbose compile settings

-h
    Display help

DESCRIPTION

The apache2 command is a wrapper script on Debian-based systems like Ubuntu for managing the Apache HTTP Server (version 2.x). It simplifies starting, stopping, restarting, and testing the robust, modular web server used to host millions of websites worldwide.

Apache2 excels in handling static/dynamic content, virtual hosts, SSL/TLS, CGI, PHP, and extensions via loadable modules. The script interacts with the underlying apache2-mpm-* binaries, PID files in /var/run/apache2/, and configurations in /etc/apache2/.

Typical workflows: Use sudo apache2 configtest to validate syntax before changes; sudo apache2 restart applies updates; sudo apache2 graceful reloads without dropping connections. Modules/sites are enabled with helper tools like a2enmod/a2ensite, symlinking configs.

Requires root privileges for control operations. Integrates with systemd via apache2.service. Logs errors to /var/log/apache2/error.log and access to access.log. Ideal for production due to its reliability and community support.

CAVEATS

Requires sudo/root for start/stop/restart. Config errors halt startup. High memory use with many modules/virtual hosts. Firewall/SELinux may block ports.

KEY PATHS

Config: /etc/apache2/apache2.conf
Sites: /etc/apache2/sites-available/
Modules: /etc/apache2/mods-available/
PID: /var/run/apache2/apache2.pid

LOGS

Error: /var/log/apache2/error.log
Access: /var/log/apache2/access.log
Use tail -f for monitoring

HISTORY

Introduced in Debian's apache2 package for Apache 2.0 (2002), succeeding Apache 1.x. Apache HTTP Server started in 1995 as a patch series; 2.x added threading, better performance. Maintained by Apache Software Foundation.

SEE ALSO

Copied to clipboard