Rank #1 on Google Maps
India English
Kenya English
United Kingdom English
South Africa English
Nigeria English
United States English
United States Español
Indonesia English
Bangladesh English
Egypt العربية
Tanzania English
Ethiopia English
Uganda English
Congo - Kinshasa English
Ghana English
Côte d’Ivoire English
Zambia English
Cameroon English
Rwanda English
Germany Deutsch
France Français
Spain Català
Spain Español
Italy Italiano
Russia Русский
Japan English
Brazil Português
Brazil Português
Mexico Español
Philippines English
Pakistan English
Türkiye Türkçe
Vietnam English
Thailand English
South Korea English
Australia English
China 中文
Somalia English
Canada English
Canada Français
Netherlands Nederlands

How to Install Apache on a Linux VPS

Buy domains, business emails, hosting, VPS and more: Get Started

Cheapest Domains in Kenya

Get your .Co.ke or .Com domain now for just 299.00 KES (Back to 1200 in 7 days)

.CO.KE for 299.00 KES | .COM for 999.00 KES

You just spun up a fresh VPS, and the terminal is sitting open in front of you. No web server is running yet, so the next few steps will decide how soon your site goes live. 

Apache tends to win out when a project needs flexible per-directory configuration (through .htaccess files) or heavy module support. 

This guide walks through the exact commands to install, configure, and verify Apache on a Linux VPS. It covers Ubuntu, Debian, CentOS, AlmaLinux, and Rocky Linux.

What You Need Before You Start

Pay Less and Manage It Yourself, or Add Server Management

Before you type a single command, check a few things first. Skipping this step often confuses later, so take two minutes here.

  • SSH access to your VPS, with root privileges or a sudo-enabled user account ready
  • Your distro is identified up front, since Ubuntu and Debian use different commands than the RHEL family.
  • Ports 80 and 443 are free and not already claimed by another service
  • At least 1GB of RAM available, since Apache’s default worker processes can strain smaller VPS plans under load

Run this command to check if port 80 is already taken:

sudo ss -tuln | grep :80

If nothing returns, the port is open, and you can move ahead.

Step 1: Update Your Server Packages First

sudo apt update && sudo apt upgrade -y

Every install should start with an update. Old package lists can pull in outdated dependencies and cause conflicts mid-install.

For Ubuntu and Debian, run:

sudo apt update && sudo apt upgrade -y

For CentOS, RHEL, AlmaLinux, or Rocky Linux, run:

sudo dnf update -y

If the update touches the kernel, reboot the server before continuing.

sudo reboot

Give it a minute, then reconnect over SSH and pick up where you left off.

Step 2: Install Apache on Ubuntu and Debian VPS

sudo apt install apache2 -y
systemctl status apache2

Ubuntu and Debian both use apt as the package manager, and Apache installs through a single command.

sudo apt install apache2 -y

Apache starts on its own right after install, so there’s no separate launch step. Confirm it’s running with this command:

systemctl status apache2

You should see “active (running)” in the output. If you do, the install worked.

A few defaults worth knowing right away:

  • Document root: /var/www/html
  • Main config file: /etc/apache2/apache2.conf
  • Service name: apache2, not httpd, and every command from here uses that name

Step 3: Install Apache on CentOS, RHEL, AlmaLinux, and Rocky Linux VPS

The RHEL family uses dnf instead of apt, and the package name changes, too.

sudo dnf install httpd -y

Unlike Ubuntu, Apache does not start on its own after installation here. Start it and set it to launch on boot in one step:

sudo systemctl enable --now httpd

Defaults to remember on this distro family:

  • Document root: /var/www/html
  • Main config file: /etc/httpd/conf/httpd.conf
  • SELinux runs in enforcing mode by default, which plays a role later when you set permissions

Step 4: Start, Enable, and Verify the Apache Service

Once Apache is installed, confirm it actually runs before moving on. Use the right command for your distro:

sudo systemctl status apache2   # Ubuntu/Debian

sudo systemctl status httpd     # RHEL family

Then open a browser and visit your server’s IP address directly, like http://your-server-ip/. A default Apache test page should load. That page confirms the install worked and the service answers on port 80.

Read the status output carefully. “active (running)” means everything is fine. “failed” or “inactive (dead)” means something needs attention. When that happens, pull more detail with:

sudo journalctl -u apache2   # Ubuntu/Debian

sudo journalctl -u httpd     # RHEL family

This log usually names the exact line or file causing the failure.

Step 5: Open Apache Ports Through Your VPS Firewall

sudo ufw allow 'Apache Full'

sudo ufw enable

sudo ufw status

A running service does nothing for visitors if the firewall blocks it. Open the right ports before you test from outside.

On Ubuntu or Debian with UFW:

sudo ufw allow 'Apache Full'

sudo ufw enable

sudo ufw status

The “Apache Full” rule opens both port 80 and port 443 in one move.

On CentOS, RHEL, AlmaLinux, or Rocky Linux with firewalld:

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

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

sudo firewall-cmd --reload

One warning before you touch any firewall on a remote VPS: allow SSH first. If you enable the firewall without an SSH rule in place, you lock yourself out instantly. Getting back in then needs console access from your hosting provider.

Step 6: Configure an Apache Virtual Host for Your Domain

A virtual host tells Apache which files belong to which domain. This step turns a bare test page into a real site.

Start by creating a dedicated document root:

sudo mkdir -p /var/www/yourdomain.com/html

Then create a config file with the basics filled in: ServerName, ServerAlias, and DocumentRoot. On Ubuntu or Debian, place it in /etc/apache2/sites-available/ and enable it with:

sudo a2ensite yourdomain.com.conf

sudo a2dissite 000-default.conf

On the RHEL family, drop the config file directly into /etc/httpd/conf.d/, since there’s no a2ensite equivalent on this distro.

Before you reload Apache, test the config for syntax errors:

sudo apache2ctl configtest   # Ubuntu/Debian

sudo httpd -t                # RHEL family

A clean “Syntax OK” means you’re ready to reload. Skipping this check is how small typos take a live site down.

Step 7: Set Correct File and Folder Permissions

Apache runs as a specific user, and that user needs the right access to read your files. Get this wrong, and visitors see a blank page or an error instead of your site.

Set ownership first:

sudo chown -R www-data:www-data /var/www/yourdomain.com   # Ubuntu/Debian

sudo chown -R apache:apache /var/www/yourdomain.com        # RHEL family

Then apply the standard permission split, directories at 755 and files at 644:

sudo find /var/www/yourdomain.com -type d -exec chmod 755 {} \;

sudo find /var/www/yourdomain.com -type f -exec chmod 644 {} \;

Loose permissions might not cause problems on a default test page. Once real site content sits in that folder, they become a risk.

Step 8: Secure Apache With an SSL Certificate

sudo apt install certbot python3-certbot-apache -y

A site without HTTPS looks outdated to visitors and to search engines alike. Certbot makes adding a free certificate a short job.

Install Certbot along with the Apache plugin:

sudo apt install certbot python3-certbot-apache -y   # Ubuntu/Debian

sudo dnf install certbot python3-certbot-apache -y    # RHEL family

Run Certbot and let it handle the virtual host edits on its own:

sudo certbot --apache

Follow the prompts, and Certbot updates your config and sets up the redirect from HTTP to HTTPS automatically. Confirm it worked by visiting your site with https:// in front of the address.

Certificates expire every 90 days, so check that auto-renewal is set up:

sudo certbot renew --dry-run

A clean dry run means renewal will happen on its own without any manual steps later.

Troubleshoot Common Apache Installation Errors on a VPS

Even a careful install hits a snag sometimes. Here are the errors people run into most often, along with the fix for each one.

1) AH00558: Could not reliably determine the server’s fully qualified domain name

This warning shows up often and does not stop Apache from running. Fix it by adding a global ServerName line:

echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf

sudo a2enconf servername

sudo systemctl reload apache2

2) AH00072: could not bind to address 0.0.0.0:80 (port already in use)

Something else already holds port 80. Find out what with:

sudo lsof -i :80

sudo ss -tlnp | grep :80

Nginx or a second Apache instance are the usual culprits. Stop the conflicting service, then start Apache again.

3) 403 Forbidden on an install that seemed to work

Start with permissions. Run ls -la on your document root and confirm the ownership and access levels match what Apache expects. Check the virtual host file too, since a missing DirectoryIndex or a restrictive Require directive can trigger this same error.

4) 403 Forbidden that sticks around after permissions look correct (RHEL family only)

SELinux context is almost always the reason on CentOS, AlmaLinux, or Rocky Linux. Reset it with:

sudo restorecon -Rv /var/www/html/

This fix is especially common after moving files in from another directory. Copied files can carry the wrong context with them.

5) Site loads over HTTP, but the SSL setup fails.

Confirm the SSL module is active before running Certbot again:

sudo a2enmod ssl

On the RHEL family, check that mod_ssl is installed alongside httpd, since it ships as a separate package.

6) Config test passes, but the reload still fails.

Look for a duplicate Listen directive or two virtual hosts claiming the same ServerName. Both are common after manual edits and won’t always show up during configtest.

Where to look next

Log files often explain what a status check alone cannot:

  • Ubuntu/Debian: /var/log/apache2/error.log
  • RHEL family: /var/log/httpd/error_log

Run sudo tail -20 on either file to see the most recent entries first.

FAQs

Is Apache free to use on a VPS?

What is the difference between Apache and Nginx on a VPS?

How long does installing Apache on a VPS actually take?

Can Apache and Nginx run on the same server at once?

Set up Apache Web Server Today

A finished Apache install means more than a package that downloaded without errors. The service runs, the right ports stay open, and your virtual host points to the correct files. SSL keeps traffic encrypted on top of that. That’s a site ready for real visitors, not just a default test page.

From here, the next steps usually involve adding PHP or a database for dynamic content. Scaling up VPS resources comes next once traffic grows.

If your current plan feels tight on RAM or storage, check a VPS plan built for that load. Apache and your application should run side by side, so the installation you just finished has room to grow.

Truehost website builder home cta

Elias N
Author

Elias N

SEO Expert Nairobi, KEN

SEO nerd by trade. Obsessing over keywords, content, and why Google does what it does.

View All Posts