How to Install Apache on Ubuntu 24.04

Install Apache on Ubuntu 24.04 – DevAnswers.net

This guide covers Ubuntu 24.04. Read the Ubuntu 26.04 edition.

We may earn a referral fee at no additional cost to you when you shop through the links on this page.

Ubuntu 24.04 LTS (Noble Numbat), released April 2024, is a stable long-term support release with security updates until May 2029 (extendable to 2034 with Ubuntu Pro). It ships with Apache 2.4 and PHP 8.3, making it an ideal choice for modern web hosting….

The following steps cover installing the Apache web server, configuring UFW firewall rules for web traffic, verifying the service, and setting up a virtual host for your domain.

Prerequisites 

Before you begin, ensure you have a server running Ubuntu 24.04 (Noble Numbat) with a non-root user that has sudo privileges, plus SSH or console access. If you are setting up a server for the first time, see our initial server setup guide for Ubuntu 24.04 (Noble Numbat).

Installing Apache 

Update the local package index to ensure the package manager has the latest information about available software versions, then install the apache2 package:

Terminal
sudo apt update && sudo apt install -y apache2

This installs Apache 2.4 from the Ubuntu 24.04 (Noble Numbat) repositories. The server starts automatically after installation.

Adjusting the Firewall 

Before testing Apache, configure a firewall to allow external access to web ports while restricting other traffic. This guide uses UFW (Uncomplicated Firewall), which works identically on Ubuntu and Debian.

If you prefer not to use a firewall (e.g., local development or behind a cloud provider’s firewall), you can skip this step entirely.

If UFW is not already installed:

Terminal
sudo apt install -y ufw
Remote server? If managing via SSH (e.g., a VPS on DigitalOcean, AWS, Linode), you must allow SSH before enabling the firewall. Skipping this will lock you out immediately.

Allow SSH connections first (if connecting remotely):

Terminal
sudo ufw allow OpenSSH

Allow Apache through the firewall:

Terminal
sudo ufw allow 'Apache Full'

Enable the firewall:

Terminal
sudo ufw enable

If you see “Command may disrupt existing ssh connections. Proceed with operation (y|n)?” Press y and Enter.

Verify the status:

Terminal
sudo ufw status

You should see Apache listed as well as OpenSSH if you’re using it.

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Apache Full                ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
Apache Full (v6)           ALLOW       Anywhere (v6)

Verifying the Installation 

Apache starts automatically after installation. Confirm the service is active:

Terminal
sudo systemctl status apache2

You should see active (running) in the output.

● apache2.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
     Active: active (running) since Mon 2026-02-02 20:00:56 GMT; 1h 13min ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 5912 (apache2)
      Tasks: 55 (limit: 503)
     Memory: 6.6M (peak: 6.8M)
        CPU: 372ms
     CGroup: /system.slice/apache2.service
             ├─5912 /usr/sbin/apache2 -k start
             ├─5915 /usr/sbin/apache2 -k start
             └─5916 /usr/sbin/apache2 -k start

Feb 02 20:00:55 devanswers.net systemd[1]: Starting apache2.service - The Apache HTTP Server...
Feb 02 20:00:56 devanswers.net apachectl[5911]: AH00558: apache2: Could not reliably determine the ser>
Feb 02 20:00:56 devanswers.net systemd[1]: Started apache2.service - The Apache HTTP Server.
On some terminals, you may need to press q to exit this screen.
If you see “Could not reliably determine the server’s fully qualified domain name,” you can safely ignore it. This won’t affect functionality.

Test locally or from a remote machine:

Don’t know your IP? Run hostname -I for your local IP, or curl -4 icanhazip.com for your public IP on a VPS.
Terminal
curl http://localhost
# or from remote:
curl http://your_server_ip

If you see HTML output in the response, the install was successful.

If you have access to a browser, you should see the default Apache placeholder page featuring the Ubuntu logo.

The default Apache welcome page is located at /var/www/html/index.html. To edit it:

Terminal
sudo nano /var/www/html/index.html

Save and exit (press CTRL + X, press Y, then press ENTER)

Managing the Apache Service 

Essential systemd commands for managing Apache:

ActionCommandNotes
Stopsudo systemctl stop apache2Halts the service completely
Startsudo systemctl start apache2Starts if stopped
Restartsudo systemctl restart apache2Full restart (brief downtime)
Reloadsudo systemctl reload apache2Graceful reload (preferred for config changes)
Enable on bootsudo systemctl enable apache2Auto-start after reboot
Use reload instead of restart in production to avoid downtime when applying configuration changes.

Important File Locations 

Key paths to know for managing Apache on Ubuntu 24.04 (Noble Numbat):

  • Default Web Root: /var/www/html — Your web content goes here.
  • Main Configuration: /etc/apache2/apache2.conf — Global configuration file.
  • Ports Configuration: /etc/apache2/ports.conf — Defines listening ports (80, 443).
  • Virtual Hosts: /etc/apache2/sites-available/ — Per-site configurations.
  • Access Log: /var/log/apache2/access.log — All requests to your server.
  • Error Log: /var/log/apache2/error.log — Errors and diagnostics.

Setting Up a Virtual Host 

To serve content for your domain instead of the default page, configure a virtual host.

Ensure your domain’s DNS A record points to your server’s public IP (configured at your domain registrar). Propagation can take up to 48 hours. For local testing, edit your /etc/hosts file on your client machine.

Create a Directory for Your Site 

Terminal
sudo mkdir -p /var/www/example.com

Create a Sample Page 

Terminal
echo '<html><head><title>Success</title></head><body><h1>Success! The Virtual Host is working.</h1><p>You can now replace this file with your own content.</p><p>Return to <a href="https://devanswers.net/series/lamp-stack/">LAMP Stack Documentation</a></p></body></html>' | sudo tee /var/www/example.com/index.html

Set Permissions 

Assign ownership to the web server user and configure group permissions:

Terminal
sudo chown -R www-data:www-data /var/www/example.com
sudo chmod -R 775 /var/www/example.com
sudo chmod -R g+s /var/www/example.com

Add your user to the www-data group so you can modify files without sudo:

Terminal
sudo usermod -aG www-data $USER
Log out and back in for the group membership to take effect. Verify with id.

Create the Virtual Host Configuration 

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

Paste the following configuration (replace example.com with your domain):

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

    <Directory /var/www/example.com>
        Options 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 and exit (press CTRL + X, press Y, then press ENTER)

Options includes only FollowSymLinks (no Indexes). This deliberately disables directory browsing for security. Enabling Indexes can expose your file structure if an index file is missing.

Enable the Site and Reload Apache 

Enable your virtual host, disable the default site, and enable the rewrite module (required for user-friendly URLs in WordPress and modern frameworks):

Terminal
sudo a2ensite example.com.conf
sudo a2dissite 000-default.conf
sudo a2enmod rewrite
sudo apache2ctl configtest && sudo systemctl reload apache2
The a2enmod output may say “you need to run: systemctl restart apache2”. A reload is sufficient here and avoids a brief service interruption.

Test It 

Visit http://example.com in your browser. As long as your domain’s A record points to your server’s IP, you should see the sample page.

Browser at http://example.com showing the sample page: Success! The Virtual Host is working.

Conclusion 

You now have Apache 2.4 running on Ubuntu 24.04 (Noble Numbat) with a configured virtual host.

Your server is ready for the next steps: installing a database server (MariaDB or MySQL), adding PHP for dynamic content, or deploying your application. For production sites, consider adding SSL/TLS encryption with Let’s Encrypt.

Next · step 2 of 4How to Install MySQL on Ubuntu 24.04
Support DevAnswers
Written, tested and maintained by one developer. Your support keeps these guides accurate and ad-light.
Buy me a coffee

Comments

Leave a reply