
httpd Command in Linux
The httpd command is used to start, stop, and control the Apache HTTP server, which is one of the most popular web servers in the world. httpd stands for HyperText Transfer Protocol Daemon, and it's the core program of the Apache HTTP server, which is responsible for serving web pages to clients (like web browsers).
- When httpd runs, it operates as a daemon, meaning it runs in the background rather than being controlled interactively by a user. This allows it to listen for incoming web requests and handle them efficiently and continuously.
- To manage multiple incoming requests simultaneously, httpd creates a pool of child processes or threads. Each child process or thread handles one request at a time, allowing the server to handle many requests concurrently.
It is generally not recommended to start httpd directly. Instead, there are better, more controlled ways to manage the server −
- Unix-based Systems − Use the apachectl command, which is a control interface for the Apache server. It simplifies starting, stopping, and managing the server.
- Windows NT, 2000, XP − Here, httpd should be run as a service. This allows it to start automatically with the system and provides more robust control and management.
- Windows 9x, ME − On older Windows versions, it runs as a console application, meaning it opens in a command prompt window and runs interactively.
Table of Contents
Here is a comprehensive guide to the options available with the httpd command −
Syntax of httpd Command
The following is the general syntax for the httpd command −
httpd [options]
httpd Command Options
The following table highlights all the fundamental options for the httpd command, which can help you manage the Apache HTTP server's operations efficiently −
Options | Description |
---|---|
-d serverroot | Sets the initial value for the ServerRoot directive to serverroot. This can be overridden by the ServerRoot directive in the configuration file. The default is /etc/httpd. |
-f config | Uses the directives in the file config on startup. If config does not begin with a /, it is considered a path relative to the ServerRoot. The default is conf/httpd.conf. |
-k start | restart | graceful | stop | graceful-stop | Signals httpd to start, restart, or stop. These commands are used to control the server. |
-C directive | Processes the configuration directive before reading config files. |
-c directive | Processes the configuration directive after reading config files. |
-D parameter | Sets a configuration parameter which can be used with <IfDefine> sections in the configuration files to conditionally skip or process commands at server startup and restart. |
-e level | Sets the LogLevel to level during server startup. This is useful for temporarily increasing the verbosity of the error messages to find problems during startup. |
-E file | Sends error messages during server startup to file. |
-R directory | Specifies the directory for shared object files when the server is compiled using the SHARED_CORE rule. |
-h | Outputs a short summary of available command line options. |
-l | Outputs a list of modules compiled into the server. This will not list dynamically loaded modules included using the LoadModule directive |
-L | Outputs a list of directives together with expected arguments and places where the directive is valid. |
-M | Dumps a list of loaded static and shared Modules. |
-S | Shows the settings as parsed from the config file (currently only shows the virtualhost settings). |
-t | Runs syntax tests for configuration files only. The program immediately exits after these syntax parsing tests with either a return code of 0 (Syntax OK) or not equal to 0 (Syntax Error). If -D DUMP_VHOSTS is also set, details of the virtual host configuration will be printed. If -D DUMP_MODULES is set, all loaded modules will be printed. |
-v | Prints the version of httpd, and then exits. |
-V | Prints the version and build parameters of httpd, and then exits. |
-X | Runs httpd in debug mode. Only one worker will be started and the server will not detach from the console. |
Windows-Specific Options −
-k install|config|uninstall | Installs Apache as a Windows NT service; changes startup options for the Apache service; and uninstalls the Apache service. |
-n name | The name of the Apache service to signal. |
-w | Keeps the console window open on error so that the error message can be read. |
Examples of httpd Command in Linux
In this section, we will look at various examples of the httpd command, which can give you a good starting point for managing your Apache HTTP server.
We will use Ubuntu as our system, and on Ubuntu, the Apache HTTP server is typically managed using the apache2 command rather than httpd.
Start the Apache HTTP Server
To start the Apache HTTP server, you can use the following command in your terminal −
sudo systemctl start apache2
This command launches the Apache server, enabling it to handle incoming web requests.

Stop the Apache HTTP Server
To stop the Apache HTTP server, you can simply use the following command −
sudo systemctl stop apache2
This command halts the Apache server, preventing it from processing any further web requests until it is restarted.

Restart the Apache HTTP Server
To restart the Apache HTTP server, you can use the following command in your terminal −
sudo systemctl restart apache2
This command stops and then starts the Apache server, effectively restarting it. This is useful when you've made changes to the configuration files and need to apply them without shutting down the server for an extended period.

Gracefully Restart the Apache HTTP Server
To gracefully restart the Apache HTTP server, you can use the following command −
sudo systemctl reload apache2
This command restarts the Apache server in a way that allows current requests to be completed before shutting down and restarting. This is useful for minimizing disruptions during maintenance or updates.

Check Configuration Syntax
To check the syntax of your Apache configuration files for any errors, you can use the following command −
sudo apache2ctl configtest
This command validates the configuration files and outputs either Syntax OK if there are no errors, or it provides details on any syntax errors that need to be corrected.

Display Server Version
To display the server version, you can simply use the httpd command with the "-v" flag −
apache2 -v
This command prints the version of the Apache HTTP server you are running.

Check the Status of the Apache HTTP Server
To check the status of the Apache HTTP server, you can use the following command in your terminal −
sudo systemctl status apache2
This command displays detailed information about the Apache service, including whether it is currently running, its status, and recent log entries.

Enable Apache to Start on Boot
To enable Apache to start on boot, use the following command in your terminal −
sudo systemctl enable apache2
This command ensures that the Apache HTTP server automatically starts whenever your system boots up. It's a handy way to make sure your server is always ready to handle requests without manual intervention.

Disable Apache from Starting on Boot
To disable Apache from starting on boot, you can simply use the following command in your terminal −
sudo systemctl disable apache2
This command prevents the Apache HTTP server from automatically starting when your system boots up. It's useful if you want to control when the server starts manually or if you're troubleshooting and need to ensure it doesn't start automatically.

Conclusion
The httpd command is a vital tool for managing the Apache HTTP server. As the core process for Apache, httpd runs as a daemon, enabling it to efficiently handle incoming web requests by creating child processes or threads for concurrent processing.
Understanding the syntax and options of the httpd command is essential, especially if you're a system administrator working with the Apache HTTP server because it enables efficient server management, troubleshooting, and optimization of web services.