Apache Commands: Manage and Troubleshoot Your Web Server

Whether you are setting up a new server or debugging a production issue, you will reach for the same handful of Apache commands over and over. Knowing them well saves time and prevents mistakes.
This guide covers the essential Apache commands for managing the service, testing configuration, working with modules and virtual hosts, and reading logs.
Before You Begin
On Ubuntu and Debian, the Apache service is named apache2. On Fedora, RHEL, and derivatives (AlmaLinux, Rocky Linux), it is named httpd. The examples below use apache2; replace it with httpd if you are on a RHEL-based system.
All commands require root or sudo privileges.
Start, Stop, Restart, and Reload Apache
The four most common service management commands are:
sudo systemctl start apache2sudo systemctl stop apache2sudo systemctl restart apache2sudo systemctl reload apache2restart stops the service and starts it again, dropping all active connections. reload tells Apache to re-read its configuration and gracefully restart worker processes without interrupting current requests. On a production server, prefer reload over restart whenever possible.
To have Apache start automatically on boot:
sudo systemctl enable apache2For a detailed walkthrough of each option, including troubleshooting tips, see How to Start, Stop, and Restart Apache on Linux .
Check Apache Status
To see whether Apache is running, use systemctl status:
sudo systemctl status apache2● apache2.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: active (running) since Mon 2026-04-07 10:15:00 UTC; 3h ago
Main PID: 4821 (apache2)
Tasks: 55 (limit: 4915)
Memory: 14.2M
CGroup: /system.slice/apache2.service
├─4821 /usr/sbin/apache2 -k start
├─4823 /usr/sbin/apache2 -k start
└─4824 /usr/sbin/apache2 -k startThe Active line confirms the service is running. The Tasks and Memory lines give a quick snapshot of resource usage.
Test the Configuration
Always test the configuration before reloading or restarting Apache. A syntax error in any configuration file can prevent the service from starting.
sudo apachectl configtestIf everything is correct, the output shows:
Syntax OKWhen there is an error, the output includes the file path and line number:
AH00526: Syntax error on line 12 of /etc/apache2/sites-enabled/example.conf:
Invalid command 'SSLCertificateFil', perhaps misspelled or defined by a module not included in the server configurationFix the reported issue before running reload or restart.
Check the Apache Version
To display the installed Apache version:
apache2 -vServer version: Apache/2.4.62 (Ubuntu)
Server built: 2025-10-01T00:00:00For more detail, including compile-time settings, use the uppercase -V flag:
apache2 -VThis shows the architecture, the default config file path, the MPM in use, and other build-time options. It is useful when debugging module compatibility or verifying how Apache was compiled.
List Loaded Modules
Apache modules add functionality such as SSL, URL rewriting, and proxy support. To see which modules are currently loaded:
apache2ctl -MLoaded Modules:
core_module (static)
so_module (static)
watchdog_module (static)
...
ssl_module (shared)
rewrite_module (shared)
proxy_module (shared)Static modules are compiled into the Apache binary. Shared modules are loaded at runtime from the configuration. If a module you expect is missing, it is either not installed or not enabled.
Enable and Disable Modules
On Ubuntu and Debian, Apache includes helper scripts for managing modules. To enable the rewrite module, for example:
sudo a2enmod rewriteTo disable it:
sudo a2dismod rewriteAfter enabling or disabling a module, restart Apache to apply the change:
sudo systemctl restart apache2On Fedora, RHEL, and derivatives, modules are managed by editing configuration files in /etc/httpd/conf.modules.d/. Comment out or uncomment the LoadModule line for the module you want to toggle, then restart the service.
Some commonly used modules include rewrite (URL rewriting), ssl (HTTPS), headers (custom HTTP headers), and proxy (reverse proxy).
List Virtual Hosts
When you manage multiple websites on the same server, virtual host configuration can get complex. To see a summary of all configured virtual hosts and their document roots:
apache2ctl -SVirtualHost configuration:
*:80 is a NameVirtualHost
default server example.com (/etc/apache2/sites-enabled/example.conf:1)
port 80 namevhost example.com (/etc/apache2/sites-enabled/example.conf:1)
port 80 namevhost staging.example.com (/etc/apache2/sites-enabled/staging.conf:1)
*:443 is a NameVirtualHost
default server example.com (/etc/apache2/sites-enabled/example-ssl.conf:1)This output shows which configuration file defines each virtual host and which port it listens on. It is one of the fastest ways to debug routing issues when a request lands on the wrong site.
Enable and Disable Sites
On Ubuntu and Debian, each virtual host configuration file lives in /etc/apache2/sites-available/. The a2ensite and a2dissite commands create or remove symlinks in /etc/apache2/sites-enabled/:
sudo a2ensite example.confsudo a2dissite 000-default.confReload Apache after making changes:
sudo systemctl reload apache2On Fedora, RHEL, and derivatives, virtual host files are placed directly in /etc/httpd/conf.d/. To disable a site, rename or remove its .conf file and reload the service.
Perform a Graceful Restart
A graceful restart lets running requests finish before the server reloads:
sudo apachectl gracefulThis is similar to systemctl reload but uses Apache-native signal handling. Worker processes that are serving active requests complete their work before shutting down, while new requests are served by processes running the updated configuration.
View Apache Logs
Apache writes two main log files: the access log (records every request) and the error log (records server and application problems).
On Ubuntu and Debian, the default log location is /var/log/apache2/. On Fedora, RHEL, and derivatives, it is /var/log/httpd/.
To watch the error log in real time:
sudo tail -f /var/log/apache2/error.logTo view the most recent access log entries:
sudo tail -20 /var/log/apache2/access.logFor a deeper look at log configuration, custom formats, and per-virtual-host logging, see Configuring the Apache Error and Access Logs .
Quick Reference
| Command | Description |
|---|---|
systemctl start apache2 | Start Apache |
systemctl stop apache2 | Stop Apache |
systemctl restart apache2 | Restart (drops connections) |
systemctl reload apache2 | Reload configuration (graceful) |
systemctl status apache2 | Show service status |
systemctl enable apache2 | Enable on boot |
apachectl configtest | Test configuration for errors |
apachectl graceful | Graceful restart |
apache2 -v | Show version |
apache2 -V | Show version and build details |
apache2ctl -M | List loaded modules |
apache2ctl -S | List virtual host configuration |
a2enmod module | Enable a module (Ubuntu/Debian) |
a2dismod module | Disable a module (Ubuntu/Debian) |
a2ensite site.conf | Enable a site (Ubuntu/Debian) |
a2dissite site.conf | Disable a site (Ubuntu/Debian) |
On Fedora, RHEL, and derivatives, replace apache2 with httpd.
Conclusion
These commands cover the day-to-day work of managing an Apache web server. For detailed service management, see How to Start, Stop, and Restart Apache . For log configuration and custom formats, see Configuring the Apache Error and Access Logs .
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page