LinuxCommandLibrary

apachectl

Control the Apache HTTP server

TLDR

Start the server

$ sudo apachectl start
copy

Restart the server
$ sudo apachectl restart
copy

Stop the server
$ sudo apachectl stop
copy

Test configuration file validity
$ apachectl configtest
copy

Check server status (requires the lynx browser)
$ apachectl status
copy

Reload configuration without dropping connections
$ sudo apachectl graceful
copy

Print full Apache configuration
$ apachectl -S
copy

Display help
$ apachectl -h
copy

SYNOPSIS

apachectl [ -k start|stop|restart|graceful|graceful-stop|configtest|fullstatus|status|dump|dumpfull|modules|vhosts ] [ -t ] [ -v ] [ -V ] [ -h ] [ -l ] [ -L ] [ -S ] [ -M ] [ -D parameter ] [ -f file ] [ -C directive ] [ -c directive ] [ -X ]

PARAMETERS

-k start
    Starts the Apache HTTP Server.

-k stop
    Stops the Apache HTTP Server.

-k restart
    Restarts the Apache HTTP Server. If the server is running, it restarts it. If the server is not running, it starts it.

-k graceful
    Gracefully restarts the Apache HTTP Server. The server handles existing connections before restarting.

-k graceful-stop
    Gracefully stops the Apache HTTP Server. The server handles existing connections before stopping.

-k configtest
    Tests the Apache HTTP Server configuration file for syntax errors.

-k fullstatus
    Shows full server status.

-k status
    Shows server status.

-k dump
    Dumps the server configuration.

-k dumpfull
    Dumps the full server configuration.

-k modules
    Lists all compiled-in modules.

-k vhosts
    Shows configured virtual hosts.

-t
    Tests the Apache HTTP Server configuration file for syntax errors. Equivalent to -k configtest

-v
    Shows the Apache HTTP Server version number.

-V
    Shows the Apache HTTP Server version and build parameters.

-h
    Shows a summary of available command-line options.

-l
    Lists all compiled-in modules.

-L
    Shows all available configuration directives.

-S
    Shows a summary of the server's virtual host configuration.

-M
    Lists all loaded modules.

-D parameter
    Defines a configuration parameter.

-f file
    Specifies an alternative configuration file.

-C directive
    Processes a configuration directive *before* reading config files.

-c directive
    Processes a configuration directive *after* reading config files.

-X
    Run in single process mode, for debugging.

DESCRIPTION

The apachectl script is a front end to the Apache HTTP Server daemon. It is designed to simplify the administration of Apache by providing a consistent interface for starting, stopping, and restarting the server.

apachectl typically resides in /usr/sbin/apachectl and is invoked with various arguments to perform specific actions. It sets up the environment and then calls the httpd binary with the appropriate parameters.

apachectl's primary function is to manage the Apache HTTP Server's lifecycle. It can be used to start the server, stop the server, restart the server (gracefully or forcefully), check the server's configuration syntax, and display the server's status. It allows users to control the web server from the command line without needing to directly interact with the httpd process. It relies on configuration files typically located in /etc/httpd/

CAVEATS

apachectl relies on the correct setting of environment variables and configuration files. Incorrect settings can lead to unexpected behavior or failure to start the server.

The exact location of configuration files and the httpd binary may vary depending on the Linux distribution.

ENVIRONMENT VARIABLES

apachectl uses environment variables such as APACHE_PID_FILE (where the PID is stored) and APACHE_RUN_DIR (where runtime files are located). Check the script itself for details.

CONFIGURATION FILES

The main configuration file is usually located at /etc/httpd/conf/httpd.conf or /etc/apache2/apache2.conf, depending on the distribution.

HISTORY

apachectl has been a standard component of the Apache HTTP Server distribution since its early versions. It provides a consistent and convenient way to manage the server's lifecycle across different platforms.

SEE ALSO

httpd(8), apache2ctl(8)

Copied to clipboard