Skip to content
Log In Sign Up info@muvcloud.com

The Short Answer

sudo apachectl configtest
sudo systemctl reload apache2    # Ubuntu and Debian
sudo systemctl reload httpd      # AlmaLinux and Rocky Linux

configtest prints Syntax OK when the files are valid; only then reload. The same check is sudo apache2ctl -t on Debian and Ubuntu and sudo httpd -t on AlmaLinux and Rocky Linux.

All the Commands

ActionUbuntu and DebianAlmaLinux and Rocky Linux
Startsudo systemctl start apache2sudo systemctl start httpd
Stopsudo systemctl stop apache2sudo systemctl stop httpd
Reloadsudo systemctl reload apache2sudo systemctl reload httpd
Restartsudo systemctl restart apache2sudo systemctl restart httpd
Statussystemctl status apache2systemctl status httpd
Start at bootsudo systemctl enable apache2sudo systemctl enable httpd

Reload or Restart?

  • Reload is a graceful restart. The main process re-reads the configuration, and the worker processes finish the requests they are serving before they are replaced. Visitors see no interruption. Use it for virtual hosts, rewrite rules, new certificates, and most other changes.
  • Restart stops Apache completely, cutting off running requests and downloads, then starts it again. Use it when you switch the MPM, for example from prefork to event, after a2enmod enables a module and asks for a restart, or when a reload did not pick up a change.

Why test first: if the configuration is broken, a restart stops Apache and then fails to start it, and every site on the server is down until you fix the file. Running configtest first turns that outage into an error message on your screen.

Check the Status

systemctl status apache2
systemctl is-enabled apache2
sudo ss -tlnp | grep -E ':80 |:443 '

The first command shows active (running) and the latest messages, the second whether Apache starts at boot, and the third which process listens on the web ports. Use httpd in place of apache2 on AlmaLinux and Rocky Linux. More ways to list services are in list services with systemctl.

When Apache Does Not Start

sudo systemctl status apache2 --no-pager -l
sudo journalctl -u apache2 -n 50 --no-pager

The journal holds the reason. Use -u httpd on AlmaLinux and Rocky Linux, and see journalctl for filtering. The usual causes:

  • Syntax error: run configtest; it names the file and the line.
  • Address already in use: another program, often Nginx, holds port 80 or 443. Find it with sudo ss -tlnp | grep ':80 ' or with lsof, then stop it or move one of the two to another port.
  • Missing certificate file: an SSLCertificateFile line points at a file that was moved or not created yet.
  • Missing module: a directive belongs to a module that is not enabled; configtest reports it as an invalid command.
  • SELinux denial on AlmaLinux and Rocky Linux: Apache may listen only on ports labeled for web servers. Label a new port instead of turning SELinux off, for example sudo semanage port -a -t http_port_t -p tcp 12345; if the port already has another label, use -m in place of -a. sudo semanage port -l | grep http_port_t lists the web ports. sudo ausearch -m avc -ts recent shows recent denials.

After It Runs Again

Once Apache is up, errors from websites go to its own files rather than the journal: /var/log/apache2/error.log on Debian and Ubuntu and /var/log/httpd/error_log on AlmaLinux and Rocky Linux. See how to read Apache access and error logs.

apachectl or systemctl?

apachectl can also start, stop, and gracefully restart Apache by itself. On a system with systemd, use systemctl for those actions so systemd keeps track of the service, and keep apachectl for checks: configtest for syntax, -S for virtual hosts, and -M for loaded modules. On AlmaLinux and Rocky Linux, apachectl hands start, stop, and restart to systemctl and accepts only a few other commands, such as configtest, so run sudo httpd -S and sudo httpd -M there.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations