Apache Commands: Manage and Troubleshoot Your Web Server

By 

Updated on

6 min read

Terminal window showing common Apache service and configuration commands on Linux

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:

Terminal
sudo systemctl start apache2
Terminal
sudo systemctl stop apache2
Terminal
sudo systemctl restart apache2
Terminal
sudo systemctl reload apache2

restart 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:

Terminal
sudo systemctl enable apache2

For 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:

Terminal
sudo systemctl status apache2
output
● 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 start

The 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.

Terminal
sudo apachectl configtest

If everything is correct, the output shows:

output
Syntax OK

When there is an error, the output includes the file path and line number:

output
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 configuration

Fix the reported issue before running reload or restart.

Check the Apache Version

To display the installed Apache version:

Terminal
apache2 -v
output
Server version: Apache/2.4.62 (Ubuntu)
Server built:   2025-10-01T00:00:00

For more detail, including compile-time settings, use the uppercase -V flag:

Terminal
apache2 -V

This 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:

Terminal
apache2ctl -M
output
Loaded 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:

Terminal
sudo a2enmod rewrite

To disable it:

Terminal
sudo a2dismod rewrite

After enabling or disabling a module, restart Apache to apply the change:

Terminal
sudo systemctl restart apache2

On 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:

Terminal
apache2ctl -S
output
VirtualHost 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/:

Terminal
sudo a2ensite example.conf
Terminal
sudo a2dissite 000-default.conf

Reload Apache after making changes:

Terminal
sudo systemctl reload apache2

On 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:

Terminal
sudo apachectl graceful

This 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:

Terminal
sudo tail -f /var/log/apache2/error.log

To view the most recent access log entries:

Terminal
sudo tail -20 /var/log/apache2/access.log

For a deeper look at log configuration, custom formats, and per-virtual-host logging, see Configuring the Apache Error and Access Logs .

Quick Reference

CommandDescription
systemctl start apache2Start Apache
systemctl stop apache2Stop Apache
systemctl restart apache2Restart (drops connections)
systemctl reload apache2Reload configuration (graceful)
systemctl status apache2Show service status
systemctl enable apache2Enable on boot
apachectl configtestTest configuration for errors
apachectl gracefulGraceful restart
apache2 -vShow version
apache2 -VShow version and build details
apache2ctl -MList loaded modules
apache2ctl -SList virtual host configuration
a2enmod moduleEnable a module (Ubuntu/Debian)
a2dismod moduleDisable a module (Ubuntu/Debian)
a2ensite site.confEnable a site (Ubuntu/Debian)
a2dissite site.confDisable 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

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