Home / Guides

Server guide

Secure Apache: A step‑by‑step guide for small businesses

If you run a VPS, dedicated or cPanel server, this guide shows you how to harden Apache. You’ll learn why it matters, how to check your current state, and what to do next.

7 min readUpdated November 2026 by the RootManage teamWorks on Ubuntu, Debian, AlmaLinux and Rocky unless noted

The short answer

Hardening Apache means disabling unnecessary modules, restricting directory access, and enforcing secure protocols. Follow these steps to reduce attack surface and keep your server resilient.

Why Apache hardening matters

An Apache server that is not hardened can expose a business to a range of attacks. Unfiltered requests can reveal directory listings, allow remote code execution, or enable denial‑of‑service by flooding the web server. Attackers often scan for default pages or misconfigured modules; once they find a vulnerability, they can steal data, deface a site, or use the server as a launchpad for further attacks. For a small business, a single compromise can damage reputation, erode customer trust, and incur downtime costs that are difficult to absorb. Hardening Apache is not just a technical exercise; it protects the core of a company’s online presence. A secure web server reduces the attack surface, limits the impact of zero‑day exploits, and helps meet compliance expectations. By applying proven configuration changes—such as disabling unused modules, restricting access to sensitive files, and enforcing secure headers—small businesses can keep their websites reliable, protect customer data, and avoid the costly aftermath of a breach.

How to audit your current Apache configuration

Begin by listing the modules that Apache loads at runtime. Knowing which modules are active helps you identify unnecessary components that could expand the attack surface. Use the Apache binary with the -M flag to produce a concise list. Compare the output against your server's functional requirements and disable any modules that are not needed for your applications. This step also confirms that security‑related modules such as mod_security and mod_ssl are present and correctly loaded.

Next, verify the SSL/TLS configuration and directory permissions. Examine the main configuration file (typically /etc/httpd/conf/httpd.conf or /etc/apache2/apache2.conf) for the SSLProtocol and SSLCipherSuite directives to ensure weak protocols and ciphers are disabled. Also, check the <Directory> blocks for proper Options, AllowOverride, and Require settings, and confirm that the document root and any included directories are not world‑writable. Tight permissions reduce the risk of unauthorized file modifications.

  • Run apachectl -M (or httpd -M) to list loaded modules.
  • Search configuration files for SSLProtocol and SSLCipherSuite directives.
  • Review <Directory> sections for Options, AllowOverride, and Require settings.
  • Check file system permissions of document roots with ls -ld.
terminal
apachectl -M   # lists enabled modules
grep -i 'SSLProtocol' -R /etc/apache2 /etc/httpd   # finds SSL protocol settings
ls -ld /var/www/html   # shows permissions of the default document root

The module list should include only what your sites need; extra modules can be disabled. SSL settings must exclude SSLv2, SSLv3, and weak ciphers. Directory permissions should show owner‑read/write and group‑read, without world‑write bits.

Step‑by‑step hardening actions

Apache can be hardened with a few simple, proven steps. First, limit the modules that load by editing the httpd.conf or apache2.conf file. Comment out or remove modules you do not need, such as mod_status, mod_autoindex, and mod_userdir. Next, enforce secure SSL/TLS settings by adding directives like SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1 and SSLCipherSuite HIGH:!aNULL:!MD5. These settings ensure only modern, strong ciphers are used. Finally, enable HTTP Strict Transport Security (HSTS) with Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" to force browsers to use HTTPS. After tightening the configuration, restart Apache with systemctl restart apache2 (Debian/Ubuntu) or systemctl restart httpd (RHEL/CentOS). Verify that the modules you removed are no longer listed by running apachectl -M. Check the SSL configuration with openssl s_client -connect yourdomain:443 -tls1_2 to confirm that only the desired protocol and ciphers are offered. Ensure HSTS is present by inspecting the response headers with curl -I https://yourdomain and looking for the Strict-Transport-Security header.

terminal
# Example commands to read before running
# Comment out unused modules in /etc/apache2/apache2.conf or /etc/httpd/conf/httpd.conf
# sudo nano /etc/apache2/apache2.conf
# Add SSL and HSTS directives
# sudo systemctl restart apache2

Check that Apache restarts cleanly and that the SSL handshake uses only the configured protocols and ciphers. Verify that the HSTS header is present in the HTTPS responses.

Common pitfalls to avoid

Many small businesses enable Apache modules that are unnecessary for their site, such as mod_php or mod_ssl, which increases the attack surface. Leaving default configuration files that expose directory listings or server signatures also makes it easier for attackers to gather information. Another common mistake is keeping the default UserDir setting or allowing mod_userdir to serve files from users’ home directories without proper permissions. These settings can lead to privilege escalation if a user’s home directory contains sensitive files. Additionally, failing to disable the ServerTokens directive or leaving it at the default Full value reveals the exact Apache version, which can be used to target known vulnerabilities. Finally, running Apache as the root user or using weak file permissions on the web root can allow an attacker to modify site files if they gain access to the server.

To avoid these pitfalls, first audit the modules loaded in httpd.conf or apache2.conf and unload any that are not required. Use ServerTokens Prod and ServerSignature Off to limit information disclosure. Disable UserDir or restrict it to specific directories with proper ownership and permissions. Run Apache under a dedicated, non-root user and set the web root permissions to 755 for directories and 644 for files. Regularly review the configuration for any changes that might re‑enable default settings.

Maintaining a hardened state

Monitoring Apache’s security posture requires regular checks of access logs, error logs, and configuration files. Use tools like logwatch or goaccess to spot repeated failed authentication attempts or unusual request patterns. Set up alerts for changes to critical files such as /etc/httpd/conf/httpd.conf or /etc/apache2/sites-enabled/*. Keep a versioned backup of the configuration directory so you can restore a known good state if a compromise is detected. Updates and backups are the backbone of long‑term security. Subscribe to the distribution’s security mailing list and apply patches within a week of release. Automate the process with yum update httpd or apt-get upgrade apache2 and schedule daily snapshots of the web root and configuration using tools like rsnapshot or bacula. Verify that backups can be restored by performing a test restore on a staging server before a production outage.

Troubleshooting after hardening

After hardening Apache you may see errors such as 403 Forbidden, 500 Internal Server Error, or the server failing to start. The first step is to check the error logs. On most Linux distributions the logs are located at /var/log/apache2/error.log or /var/log/httpd/error_log. Look for messages that reference file permissions, missing modules, or syntax errors in the configuration files. If the log shows a permission denied on a directory that should be accessible, verify that the ownership and mode match the user running the Apache process (typically www-data or apache).

If the server fails to start, run apachectl configtest or apache2ctl configtest to validate the syntax of all configuration files. The output will point to the exact file and line number where the error occurs. Common issues after hardening include disabling mod_rewrite or mod_alias without updating virtual host files, or changing DocumentRoot permissions. Once you identify the problem, correct the configuration, reload Apache with systemctl reload apache2 and confirm the site is accessible.

Best practices for production servers

Keep your Apache configuration clean and minimal. Disable unnecessary modules like mod_status or mod_info on live servers to reduce the attack surface. Ensure that directory listing is disabled globally using Options -Indexes. Regularly review your httpd.conf and virtual host files to confirm that only required directives are active. This prevents information leakage and stops attackers from guessing file paths or accessing sensitive system files that should remain hidden from public view.

Maintain a strict update schedule for both your operating system and Apache software. Apply security patches promptly to fix known vulnerabilities before they can be exploited. Monitor your access and error logs daily for unusual patterns, such as repeated 404 errors or suspicious user agents. Use automated tools to alert you on failed login attempts or unexpected configuration changes. Consistent monitoring helps you detect anomalies early and respond quickly to potential threats targeting your production environment.

  • Disable directory listing with Options -Indexes
  • Remove or disable unused Apache modules
  • Review logs for suspicious activity daily
  • Apply OS and Apache patches regularly
terminal
# Example: Check if directory listing is disabled in a virtual host
# Read these commands carefully before running them on your server
apachectl -t -D DUMP_VHOSTS | grep -i "options"

Look for lines containing Options in the output. You should see -Indexes listed to ensure directory browsing is off. If you see +Indexes or no Options directive, review your virtual host configuration to explicitly disable it.

If you would rather have engineers do this for you, see Linux server management, Windows server management or emergency malware cleanup.

Questions people ask

What modules should I disable in Apache?

Disable unused modules like `mod_status`, `mod_info`, and `mod_autoindex` to reduce attack surface. Keep only necessary features active. Check your current load with `apachectl -M` and edit your `httpd.conf` or virtual host files to remove unneeded includes.

How do I enforce HTTPS only on my site?

Use the `mod_rewrite` module to redirect all HTTP traffic to HTTPS. Add rewrite rules in your `.htaccess` or virtual host configuration to force the secure protocol. Ensure your SSL certificate is valid and properly installed to avoid browser warnings.

Can I use .htaccess to block all bots?

No, `.htaccess` cannot reliably block all bots. Many legitimate crawlers use standard user agents, and malicious bots often spoof identities. For better protection, use IP-based blocking, rate limiting, or a Web Application Firewall to manage traffic effectively.

How often should I update my Apache configuration?

Review and update your Apache configuration whenever you change server software, add new sites, or apply security patches. Regularly audit settings after major OS updates. Keep a version-controlled copy of your config files to track changes and ensure consistency.

Want a person to look at it?

Tell us what you see. We reply with what we think is wrong and what it would take to fix it.