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:
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 UFW is not already installed:
sudo apt install -y ufw
Allow SSH connections first (if connecting remotely):
sudo ufw allow OpenSSH
Allow Apache through the firewall:
sudo ufw allow 'Apache Full'
Enable the firewall:
sudo ufw enable
If you see “Command may disrupt existing ssh connections. Proceed with operation (y|n)?” Press y and Enter.
Verify the status:
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:
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.
Test locally or from a remote machine:
hostname -I for your local IP, or curl -4 icanhazip.com for your public IP on a VPS. 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:
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:
| Action | Command | Notes |
|---|---|---|
| Stop | sudo systemctl stop apache2 | Halts the service completely |
| Start | sudo systemctl start apache2 | Starts if stopped |
| Restart | sudo systemctl restart apache2 | Full restart (brief downtime) |
| Reload | sudo systemctl reload apache2 | Graceful reload (preferred for config changes) |
| Enable on boot | sudo systemctl enable apache2 | Auto-start after reboot |
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.
/etc/hosts file on your client machine. Create a Directory for Your Site
sudo mkdir -p /var/www/example.com
Create a Sample Page
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:
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:
sudo usermod -aG www-data $USER
id. Create the Virtual Host Configuration
sudo nano /etc/apache2/sites-available/example.com.conf
Paste the following configuration (replace example.com with your domain):
<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):
sudo a2ensite example.com.conf
sudo a2dissite 000-default.conf
sudo a2enmod rewrite
sudo apache2ctl configtest && sudo systemctl reload apache2
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.

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.
Comments