RackUp IT - View Cloud Hosting Plans

Get started now or speak directly with our engineering team for specialized assistance.

Logo
DevelopmentWEB & APPCalculatorTOOLServicesProductBlogOur TeamCareers
View Plans
Home>Blog>How to Install and Set Up Apache on Ubuntu (24.04 and 22.04)
Server Stack

How to Install and Set Up Apache on Ubuntu (24.04 and 22.04)

Alex Vance
Alex Vance
Published Nov 22, 2026•✓ Verified Expert Reviewed•4 min read
Install Apache on Ubuntu cover

Key Takeaways

  • ✓Install with sudo apt install apache2; it starts automatically.
  • ✓Allow 'Apache Full' in UFW to open ports 80 and 443.
  • ✓Each site gets a virtual host in /etc/apache2/sites-available.
  • ✓Certbot's Apache plugin adds free HTTPS and renews it automatically.

Table of Contents

  • •How to Install and Set Up Apache on Ubuntu (24.04 and 22.04)
  • •Step 1: Install Apache
  • •Step 2: Open the Firewall
  • •Step 3: Create a Virtual Host for Your Domain
  • •Step 4: Add HTTPS With Certbot
  • •Step 5: Add PHP (Optional)
  • •Everyday Apache Commands
  • •Where Apache Keeps Things on Ubuntu
  • •Troubleshooting
  • •Apache or Nginx?
  • •Frequently Asked Questions
  • •Your Own Ubuntu Server

How to Install and Set Up Apache on Ubuntu (24.04 and 22.04)

Apache is still one of the most widely used web servers, and it’s the default choice for PHP applications that rely on .htaccess files, including WordPress. On Ubuntu it installs from the standard repositories in one command. This guide covers installing Apache, opening the firewall, setting up a virtual host for your domain, adding free HTTPS with Certbot, and the commands you’ll use every day.

Quick answer: sudo apt update && sudo apt install apache2, then sudo ufw allow 'Apache Full', create a virtual host in /etc/apache2/sites-available/, enable it with a2ensite, and run sudo certbot --apache for HTTPS.

Step 1: Install Apache

sudo apt update
sudo apt install apache2

The service starts automatically. Check it:

sudo systemctl status apache2
apache2 -v

Open http://YOUR_SERVER_IP in a browser and you should see the “Apache2 Default Page”.

Step 2: Open the Firewall

If UFW is enabled, Apache registers application profiles you can allow by name:

sudo ufw app list
sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'
sudo ufw enable
sudo ufw status

Apache Full opens ports 80 and 443. Allow OpenSSH first so you don’t lock yourself out. On a cloud server, also check the provider’s firewall or security group; our guide to opening ports on a VPS covers both.

Step 3: Create a Virtual Host for Your Domain

Each site gets its own folder and its own configuration file. Create the web root and a test page:

sudo mkdir -p /var/www/example.com/public_html
sudo chown -R $USER:$USER /var/www/example.com/public_html
echo '<h1>It works</h1>' > /var/www/example.com/public_html/index.html

Create /etc/apache2/sites-available/example.com.conf:

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

    <Directory /var/www/example.com/public_html>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>

AllowOverride All lets .htaccess files work, which WordPress and many PHP apps need. Enable the site, enable mod_rewrite, disable the default site, test and reload:

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

configtest should print Syntax OK. Point your domain’s DNS A record at the server, then visit http://example.com.

Step 4: Add HTTPS With Certbot

sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d example.com -d www.example.com

Certbot gets a free Let’s Encrypt certificate, creates the HTTPS virtual host and can add the HTTP to HTTPS redirect for you. Renewal is automatic; test it with sudo certbot renew --dry-run.

Step 5: Add PHP (Optional)

To run PHP applications with Apache’s PHP module:

sudo apt install php libapache2-mod-php php-mysql
sudo systemctl restart apache2

For better performance under load, many setups use PHP-FPM with Apache’s event MPM instead (php-fpm plus a2enconf php*-fpm and a2enmod proxy_fcgi).

Everyday Apache Commands

TaskCommand
Test the configurationsudo apache2ctl configtest
Reload without dropping connectionssudo systemctl reload apache2
Restartsudo systemctl restart apache2
Enable / disable a sitesudo a2ensite name / sudo a2dissite name
Enable / disable a modulesudo a2enmod name / sudo a2dismod name
List loaded modulesapache2ctl -M
Follow the error logsudo tail -f /var/log/apache2/error.log

Where Apache Keeps Things on Ubuntu

  • /etc/apache2/apache2.conf: main configuration.

  • /etc/apache2/sites-available/ and sites-enabled/: virtual hosts (enabled ones are symlinks).

  • /etc/apache2/mods-available/ and mods-enabled/: modules.

  • /var/www/: web roots.

  • /var/log/apache2/: access and error logs.

Troubleshooting

  • Port 80 already in use: another web server (often Nginx) is running. Check with sudo ss -tlnp | grep :80.

  • 403 Forbidden: the <Directory> block is missing Require all granted, or file permissions stop Apache reading the folder.

  • .htaccess rules ignored: AllowOverride is None or mod_rewrite isn’t enabled.

  • Still seeing the default page: the default site is still enabled or ServerName doesn’t match the domain.

Apache or Nginx?

Apache shines with .htaccess and per-directory configuration; Nginx is lighter for static files and as a reverse proxy. Many servers run Nginx in front of Apache or PHP-FPM. If you’re deciding, see our comparison of Caddy and Nginx and the guide to common Nginx errors.

Frequently Asked Questions

What is the Apache package called on Ubuntu?
apache2. Install it with sudo apt install apache2.

How do I check if Apache is running?
Run sudo systemctl status apache2, or open the server’s IP address in a browser.

Where is the Apache web root on Ubuntu?
The default is /var/www/html. For your own sites, create a folder under /var/www and point a virtual host at it.

How do I enable .htaccess in Apache?
Set AllowOverride All in the site’s Directory block and enable mod_rewrite with sudo a2enmod rewrite, then reload Apache.

How do I get HTTPS on Apache for free?
Install certbot and python3-certbot-apache, then run sudo certbot --apache -d yourdomain.com.

Your Own Ubuntu Server

RackUp’s Developer VPS gives you root access to install Apache, PHP and anything else: 8 vCPU, 12 GB RAM, 150 GB NVMe and 32 TB of monthly bandwidth for $35 a month. Just want WordPress on Apache without the setup? Cloud WordPress runs it for you from $2.49 a month. See plans.

← Previous ArticleWhere to Host a React App in 2026: Static, SSR or Full-StackNext Article →VPS vs Cloud Hosting: What’s the Difference and Which Do You Need?
Interactive 60-Second Tool

Unsure Which Cloud Hosting Plan Fits Your Site?

Answer 4 quick diagnostic questions to estimate the server CPU, RAM and storage you need with transparent pricing.

Free Migration 99.9% Uptime Target
Calculate My Hosting Build
Alex Vance
Written ByAlex Vance

Cloud Infrastructure Engineer.

99.9% Uptime Target

RackUp IT - View Cloud Hosting Plans

View Hosting Plans

View Hosting Plans

CONTENTS

  • How to Install and Set Up Apache on Ubuntu (24.04 and 22.04)
  • Step 1: Install Apache
  • Step 2: Open the Firewall
  • Step 3: Create a Virtual Host for Your Domain
  • Step 4: Add HTTPS With Certbot
  • Step 5: Add PHP (Optional)
  • Everyday Apache Commands
  • Where Apache Keeps Things on Ubuntu
  • Troubleshooting
  • Apache or Nginx?
  • Frequently Asked Questions
  • Your Own Ubuntu Server

Categories

  • VPS Hosting
  • DevOps & Tutorials
  • WordPress Hosting
  • Cloud Hosting
  • Server Stack
  • Networking & Security
  • Web Hosting / Managed Cloud
  • E-Commerce
  • Hosting & SEO
  • Hosting Benchmarks
  • Cloud Backup & DevOps
  • Managed VPS

Recent Posts

  • Vultr Alternatives in 2026: VPS Hosting for Developers Compared
  • Docker Port Mapping Explained: -p, EXPOSE and Compose ports
  • Bluehost Alternatives (2026): WordPress Hosting Without the Renewal Price Jump

Tags

ApacheUbuntuLinuxWeb ServerTutorial

Related Posts

Nginx redirect HTTP to HTTPS coverServer Stack
Nov 20, 2026

Nginx: Redirect HTTP to HTTPS (and www to non-www) the Right Way

The correct Nginx server blocks for HTTP to HTTPS and www to non-www redirects, Certbot's --redirect, HSTS, testing with curl, and fixing redirect loops.

Read Article →
Traefik vs Caddy vs Nginx coverServer Stack
Nov 4, 2026

Traefik vs Caddy vs Nginx: Which Reverse Proxy Should You Use?

Traefik routes Docker containers automatically, Caddy does HTTPS with almost no config, and Nginx does everything. Which reverse proxy fits your setup.

Read Article →
Nginx monitoring coverServer Stack
Nov 2, 2026

Nginx Monitoring: stub_status, Logs, Prometheus and Alerts

Set up Nginx monitoring with the built-in stub_status page and timed access logs, then add Prometheus, Grafana and the alerts that catch problems early.

Read Article →
Logo

Expert Web & App Development, UI/UX Design, Branding, and Consulting to scale your business.

Company

  • About Us
  • Blog
  • Contact
  • Our Team
  • Careers

Services

  • Web Development
  • App Development
  • UI/UX Design
  • Consulting
  • Managed WordPress VPS
  • Website Speed Test

Subscribe to our newsletter

We accept
  • bKash
  • Nagad
  • Rocket
  • Upay
  • CellFin
  • Meghna Pay
  • OK Wallet
  • Tap
  • mCash
  • DBBL Nexus
  • Visa
  • Mastercard
  • American Express
  • Crypto
Pay with Visa, Mastercard, American Express, DBBL Nexus, CellFin, Rocket, bKash, Tap, Meghna Pay, Nagad, mCash, Upay and OK Wallet. Verified by EPS

© 2026 Rackup IT Solution. All rights reserved.

Privacy PolicyTerms of Service