LochStudios  /  Help Centre  /  VPS & Linux  /  Install Apache2 on Ubuntu/Debian

Install Apache2 on Ubuntu/Debian

Install Apache2 from apt on a LochStudios Ubuntu or Debian VPS, start the service, and confirm HTTP on the IPv4 in the portal.

Updated

Apache2 is the web server we use on a LochStudios KVM VPS when you want the classic Apache layout, .htaccess, or a LAMP stack. This article installs the package from Ubuntu or Debian apt, starts it, and checks that the default page answers on this server's IPv4.

This is for a LochStudios KVM VPS. Credentials, the IPv4, and an out-of-band console sit on that server in the portal. Sign in at the portal, open the VPS service, and copy the login from there. Do not guess a hostname.

On Beginner and Standard shared hosting (cPanel) you do not install Apache yourself. Open the hosting service and click Log in to cPanel. That account already runs Apache.

If you also need MariaDB and PHP in the same sitting, use Install a LAMP stack instead of this article alone.

Before you install

  1. Sign in at the portal, open the VPS service, and copy the IPv4, username, and password.
  2. Connect over SSH.

- Windows: Connect to your VPS via SSH from Windows
- macOS or Linux: Connect to your VPS via SSH from macOS or Linux

  1. Patch the image and use a sudo user for daily work: First steps on a new VPS.

If SSH from your computer will not connect, open the console on the same service. That session does not need port 22 from your network.

Do not install Apache on a box that already has Nginx listening on port 80. One process owns that port. If you want Nginx instead, see Install Nginx on Ubuntu/Debian.

Update package lists

sudo apt update

Install Apache2

sudo apt install -y apache2

On AlmaLinux or Rocky Linux the package is httpd:

sudo dnf install -y httpd

Debian-style site files live under /etc/apache2/sites-available/ and /etc/apache2/sites-enabled/. AlmaLinux and Rocky Linux use /etc/httpd/conf/ and /etc/httpd/conf.d/ instead. The rest of this article uses the Ubuntu and Debian layout.

Start and enable Apache2

sudo systemctl start apache2
sudo systemctl enable apache2

enable starts Apache2 again after a reboot.

On AlmaLinux or Rocky Linux:

sudo systemctl start httpd
sudo systemctl enable httpd

Confirm it is running

sudo systemctl status apache2

You should see active (running).

From the server itself:

curl -I http://127.0.0.1

You should get HTTP/1.1 200 (or HTTP/1.1 301 if you already forced HTTPS). The default page on Ubuntu and Debian is served from /var/www/html.

Open it in a browser

Use the IPv4 on the VPS service in the portal:

http://203.0.113.10

Replace that address with yours. You should see the Apache2 default page.

If the service is running and curl on the server works, but your browser does not, the host firewall is usually still closed on port 80.

Allow HTTP and HTTPS on UFW

UFW is the host firewall on our Ubuntu images. Allow SSH before you enable it, or you will cut off SSH from your computer. The console in the portal still works if that happens.

If UFW is already active:

sudo ufw allow 'Apache Full'
sudo ufw status

Apache Full is the package profile for ports 80 and 443. HTTP only:

sudo ufw allow 'Apache'

If UFW is still inactive, do not run sudo ufw enable from this article. Set the defaults and allow SSH first: Set up a UFW firewall on Ubuntu. That guide then opens 80 and 443 the same way.

On AlmaLinux or Rocky Linux, open the ports with firewalld if that service is running:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Everyday commands

Reload after a config change (keeps current connections):

sudo systemctl reload apache2

Restart:

sudo systemctl restart apache2

Stop:

sudo systemctl stop apache2

Check the config before you reload:

sudo apache2ctl -t

Only reload when that prints Syntax OK.

Enable a module (for example rewrite for .htaccess RewriteRule):

sudo a2enmod rewrite
sudo systemctl reload apache2

Where the files live (Ubuntu and Debian)

  • Main config: /etc/apache2/apache2.conf
  • Site configs you edit: /etc/apache2/sites-available/
  • Sites Apache actually loads: /etc/apache2/sites-enabled/ (symlinks)
  • Ports: /etc/apache2/ports.conf
  • Default document root: /var/www/html
  • Error log: /var/log/apache2/error.log

Leave the default site in place until you have a virtual host that answers. Then add your own site: Set up Apache virtual hosts.

There is no AutoSSL on a stock VPS. After the name points at this IPv4, issue TLS with Certbot.

If Apache will not start

Address already in use on port 80 or 443

Something else is bound there (often Nginx). Check:

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

Stop the other web server, or pick one stack and stay with it.

apache2.service failed after a config edit

sudo apache2ctl -t
sudo journalctl -u apache2 -n 50 --no-pager

Fix the file apache2ctl -t names, then sudo systemctl start apache2.

Browser cannot reach the default page

  1. sudo systemctl is-active apache2 should print active.
  2. curl -I http://127.0.0.1 should succeed on the server.
  3. sudo ufw status should allow 80/tcp (and 443/tcp once you want HTTPS).
  4. Browse to the IPv4 shown on the VPS in the portal, not a hostname you have not pointed yet.

Still stuck? Open a support ticket. Tell us the VPS service and what sudo systemctl status apache2 and sudo apache2ctl -t printed.

Next


Was this article helpful?

← Back to VPS & Linux