Root Servers

Install the Apache web server (Debian & Ubuntu)

Install Apache on your root server, set up your own domain, a free Let’s Encrypt SSL certificate, PHP, the firewall and basic hardening – step by step.

  • 6 min read
  • Updated November 1, 2026

01 Requirements

This guide works on Debian 12 and 13 and Ubuntu 22.04 and 24.04 LTS. You need:

  • a root server (KVM) with a fresh Debian or Ubuntu installation,
  • the IP address and the root password or your SSH key – you find both with your server in the customer center,
  • for your own domain with HTTPS: a domain whose A record (and AAAA record for IPv6) points to your server’s IP.

In the examples, example.com stands for your domain and 203.0.113.10 for your server’s IP – replace both with your own values.

02 Connect via SSH

On Windows open Command Prompt or PowerShell, on macOS and Linux the Terminal, and connect as root:

ssh root@203.0.113.10

On the first connection SSH asks whether you trust the server – confirm with yes. Run all following commands on the server.

If you are logged in as a regular user instead of root, put sudo in front of every command.

03 Update the system

First bring all packages up to date:

apt update && apt upgrade -y

If a new kernel was installed, restart the server with reboot and connect again.

04 Install Apache

apt install apache2 -y

Apache starts automatically after the installation and also after every reboot. Check that it is running:

systemctl status apache2

The output should show active (running). Press q to leave the view.

05 Set up the firewall

We recommend the ufw firewall. It is preinstalled on Ubuntu; on Debian install it with apt install ufw -y.

Important: allow SSH (port 22) before you enable the firewall – otherwise you lock yourself out.

ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
ufw status

Port 80 is HTTP, port 443 is HTTPS. If you changed your SSH port, allow that port instead of 22.

06 Test in the browser

Open http://203.0.113.10 (your server’s IP) in your browser. You see the “Apache2 Debian Default Page” or “Apache2 Ubuntu Default Page” – Apache is running.

This page is located at /var/www/html/index.html. For a single website you could put your files right there. For your own domain, set up a virtual host instead (next step).

07 Set up your own domain (virtual host)

Virtual hosts let one Apache serve any number of websites – each in its own folder. First create the folder for the website:

mkdir -p /var/www/example.com/public_html
echo '<h1>example.com is working!</h1>' > /var/www/example.com/public_html/index.html
chown -R www-data:www-data /var/www/example.com

Then create the configuration (nano is a simple editor; if it is missing: apt install nano -y):

nano /etc/apache2/sites-available/example.com.conf

Paste this content:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html

    <Directory /var/www/example.com/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
    CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>

Save with Ctrl+O and Enter, exit with Ctrl+X. Enable the site, disable the default site, check the configuration and reload Apache:

a2ensite example.com.conf
a2dissite 000-default.conf
apache2ctl configtest
systemctl reload apache2

apache2ctl configtest must report Syntax OK. As soon as your domain points to the server, your new site is available at http://example.com.

  • Options -Indexes prevents visitors from seeing a file list of folders without an index.html.
  • AllowOverride All allows .htaccess files – many CMS such as WordPress need this.

08 HTTPS with Let’s Encrypt

A Let’s Encrypt SSL certificate is free and renews automatically. Install Certbot with the Apache plugin:

apt install certbot python3-certbot-apache -y

Request the certificate – Certbot adjusts the Apache configuration itself and sets up the redirect from HTTP to HTTPS:

certbot --apache -d example.com -d www.example.com

The first time, Certbot asks for an email address for expiry notices and for your agreement to the Let’s Encrypt terms of service. Your site is then available at https://example.com.

Certificates are valid for 90 days and are renewed automatically by a system service. Test the renewal once:

certbot renew --dry-run

Certbot can only issue the certificate if the domain already points to your server and port 80 is reachable. After a DNS change it can take some time until it has propagated everywhere.

09 Install PHP (optional)

For WordPress, shops or your own PHP applications, install PHP with the most common extensions:

apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-zip -y
systemctl restart apache2
php -v

You get the PHP version of your distribution, for example PHP 8.2 on Debian 12, PHP 8.4 on Debian 13 and PHP 8.3 on Ubuntu 24.04. To test it, briefly create an info page:

echo '<?php phpinfo();' > /var/www/example.com/public_html/info.php

Open https://example.com/info.php – you see the PHP overview. Delete the file afterwards, because it reveals details about your server:

rm /var/www/example.com/public_html/info.php

10 Important modules

Modules extend Apache. These are the ones you need most often:

a2enmod rewrite headers expires
systemctl restart apache2
  • rewrite – clean URLs and redirects in .htaccess (needed by almost every CMS),
  • headers – custom HTTP headers, for example security headers,
  • expires – browser caching for images, CSS and JavaScript.

apache2ctl -M lists active modules; disable a module with a2dismod name.

11 Harden Apache

By default, Apache reveals its version and operating system in error pages and HTTP headers. Open the security settings:

nano /etc/apache2/conf-available/security.conf

Change these two lines to the following values:

ServerTokens Prod
ServerSignature Off

Optionally add useful security headers (requires the headers module):

Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "strict-origin-when-cross-origin"

Then check and reload:

apache2ctl configtest && systemctl reload apache2
  • Keep the system up to date – set up automatic security updates with apt install unattended-upgrades -y.
  • Use a key instead of a password for SSH.
  • Give files only to the www-data user and never use 777 permissions.

12 Important commands and files

Command / pathPurpose
systemctl reload apache2Reload the configuration without dropping open connections
systemctl restart apache2Restart Apache (needed after module changes)
systemctl stop / start apache2Stop or start Apache
apache2ctl configtestCheck the configuration for errors – always before a reload
apache2ctl -SList all active virtual hosts
a2ensite / a2dissiteEnable / disable a website
a2enmod / a2dismodEnable / disable a module
/etc/apache2/apache2.confMain configuration
/etc/apache2/sites-available/Website configurations (active ones are linked in sites-enabled/)
/var/www/Your website files
/var/log/apache2/Access and error logs

13 Troubleshooting

Apache does not start

Show the latest messages – they usually contain the line with the error:

apache2ctl configtest
journalctl -u apache2 --no-pager -n 50

“Address already in use” – port 80 is taken

Another web server (for example Nginx) is already using the port. Find it with:

ss -tlnp | grep -E ':80|:443'

Stop or remove the other service, for example systemctl disable --now nginx.

403 Forbidden

Apache is not allowed to read the files, or an index.html/index.php is missing. Check the DocumentRoot path and reset the ownership: chown -R www-data:www-data /var/www/example.com.

Site not reachable

  • Firewall: are ports 80 and 443 allowed (ufw status)?
  • DNS: does the domain point to the right IP? Check with dig +short example.com (package dnsutils) or an online DNS check.
  • Look at the error log: tail -f /var/log/apache2/error.log

Certbot fails

Almost always the domain does not point to the server yet or port 80 is blocked. Check DNS and the firewall and run certbot --apache again.

Still stuck?

Our support team helps you

Open a ticket in the customer center – we reply in English or German.