How to Fix ‘Job for apache2.service Failed’ in Ubuntu

Attempting to start or reload the Apache web server on an Ubuntu server or desktop (via systemctl start apache2 or service apache2 restart) only to be met with the error “Job for apache2.service failed because the control process exited with error code. See ‘systemctl status apache2.service’ and ‘journalctl -xeu apache2.service’ for details” is a critical administrative halt. The web server remains offline, dropping all incoming HTTP and HTTPS requests.

Because systemd acts as a generic supervisor, the error message itself does not explain what went wrong. The actual failure stems from syntax errors inside Apache configuration files (/etc/apache2/apache2.conf or sites-enabled/*.conf), TCP Port 80 or 443 already bound by another daemon (such as Nginx), missing SSL/TLS certificate files, or incorrect file permissions on web root directories.

Failure Point Technical Mechanism Targeted Resolution
Configuration Syntax Error Unclosed XML tags, invalid directives, or typos in virtual host files Run apache2ctl configtest to locate exact line syntax error
Port Collision (80/443 in Use) Another service (Nginx, Lighttpd, Docker proxy) already bound to port Identify and terminate conflicting socket listeners via ss / netstat
Missing SSL Certificate / Key SSLCertificateFile directive points to non-existent or unreadable file Correct certificate file paths or update Let’s Encrypt symlinks
Missing Log Directory / Permissions /var/log/apache2 is deleted or owned by wrong user account Recreate directory and restore www-data ownership

Method 1: Run the Apache Syntax Test Utility (apache2ctl configtest)

The single most powerful diagnostic command for Apache is its built-in configuration validator, which parses all enabled configuration files and reports the exact line number of any syntax error.

  1. Open your terminal shell.
  2. Execute the syntax test command:
    sudo apache2ctl configtest
  3. Review the output:
    • If it outputs Syntax OK, your configuration files are syntactically valid (proceed to Method 2).
    • If it outputs an error (e.g. Syntax error on line 28 of /etc/apache2/sites-enabled/example.conf: Invalid command 'SSLEngine'), note the file path and line number.
  4. Open the offending file:
    sudo nano /etc/apache2/sites-enabled/example.conf
  5. Correct the typo or enable the missing module (e.g. sudo a2enmod ssl), save the file, and re-run sudo apache2ctl configtest until it reports Syntax OK.

Method 2: Check for Port 80 and 443 Conflicts (Address Already in Use)

If another web server (such as Nginx) or a containerized proxy is already listening on port 80 or 443, Apache cannot bind to the socket, aborting with (98)Address already in use: AH00072: make_sock: could not bind to address.

  1. Inspect active listeners on HTTP and HTTPS ports using ss:
    sudo ss -tulpn | grep -E ':80|:443'
  2. Review the rightmost column to see which process holds the port (e.g. nginx or caddy).
  3. If Nginx is running and not needed, stop and disable it:
    sudo systemctl stop nginx
    sudo systemctl disable nginx
  4. Alternatively, change Apache’s listening ports inside /etc/apache2/ports.conf if running both servers simultaneously as a reverse proxy.
  5. Attempt to start Apache again:
    sudo systemctl start apache2

Method 3: Inspect Detailed systemd Journal Logs

If configuration syntax passes but Apache still fails to spawn worker processes, inspecting systemd journal logs reveals runtime initialization crashes.

  1. Execute the journalctl utility:
    sudo journalctl -xeu apache2.service --no-pager -n 50
  2. Scroll through the log entries. Look for critical alerts such as:
    • AH00526: Syntax error... SSLCertificateFile: file does not exist (indicates expired or moved SSL certificates).
    • (13)Permission denied: AH00091: apache2: could not open error log file (indicates file permission locks).

Method 4: Verify and Restore Apache Log Directory Permissions

Apache requires write access to /var/log/apache2 to create its error and access logs before initializing worker processes. If this folder was inadvertently removed during system cleanup, Apache refuses to start.

  1. Check if the log directory exists:
    ls -ld /var/log/apache2
  2. If the directory is missing, recreate it:
    sudo mkdir -p /var/log/apache2
  3. Set the appropriate ownership and permissions:
    sudo chown -R root:adm /var/log/apache2
    sudo chmod 750 /var/log/apache2
  4. Restart the service:
    sudo systemctl restart apache2

Method 5: Disable Broken Virtual Hosts Sequentially

If multiple domain configuration files exist and you cannot immediately pinpoint which one is preventing startup, disable all custom virtual hosts and test with the default configuration.

  1. Disable non-essential virtual host files:
    sudo a2dissite *.conf
  2. Re-enable the default test page:
    sudo a2ensite 000-default.conf
  3. Start the Apache service:
    sudo systemctl start apache2
  4. If Apache starts successfully, re-enable your virtual hosts one by one (sudo a2ensite domain.conf) while reloading the service after each to isolate the broken configuration.

Preventing Web Server Startup Failures

Always execute sudo apache2ctl configtest before reloading Apache after editing virtual host files or renewing SSL certificates via Let’s Encrypt Certbot. Incorporating this verification step into your deployment scripts prevents production downtime by catching misconfigurations before the live service process is interrupted.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.