Install Apache on Ubuntu 24.04 with sudo apt install apache2, allow web traffic in the firewall, then open your server's IP address in a browser.
Install Apache
Update the package list, then install the apache2 package:
sudo apt update
sudo apt install apache2
Ubuntu starts Apache right after the installation and starts it again after every reboot. Check that it's running:
sudo systemctl status apache2
Look for active (running) in green. Press q to leave the status screen.
Allow web traffic in the firewall
Ubuntu's firewall is UFW. Apache adds three profiles to it:
| Profile | Opens |
|---|---|
Apache | Port 80 (HTTP) |
Apache Secure | Port 443 (HTTPS) |
Apache Full | Ports 80 and 443 |
Allow SSH first, so you don't lock yourself out, then allow both web ports:
sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'
If UFW isn't switched on yet, switch it on and confirm with y:
sudo ufw enable
Check the rules. You should see OpenSSH and Apache Full with ALLOW:
sudo ufw status
If SSH on your server uses a port other than 22, allow that port instead of OpenSSH (for example sudo ufw allow 2222/tcp).
Check that Apache works
Open http://your-server-ip in your browser (for example http://203.0.113.10). You should see the Apache2 Default Page with the words "It works!".
You can also test from the server itself. The first line of the answer should be HTTP/1.1 200 OK:
curl -I http://localhost
Start, stop and reload Apache
sudo systemctl reload apache2 # load changed settings without dropping visitors
sudo systemctl restart apache2 # full restart
sudo systemctl stop apache2 # stop
sudo systemctl start apache2 # start
sudo apache2ctl configtest # check the settings for errors
Run sudo apache2ctl configtest after every change. It should end with Syntax OK; only then reload.
Where Apache keeps its files
| Path | What it is |
|---|---|
/var/www/html | The default website (the "It works!" page) |
/etc/apache2/apache2.conf | Main settings file |
/etc/apache2/sites-available/ | One file per website (virtual host); turn on with a2ensite |
/etc/apache2/mods-available/ | Modules; turn on with a2enmod, for example sudo a2enmod rewrite |
/var/log/apache2/access.log | Every request to the server |
/var/log/apache2/error.log | Errors: look here first when something fails |
To put your own website on the server, give it its own folder and settings file instead of using /var/www/html. That way you can add more sites later: see Host several websites on one server with Apache.
Common problems
The browser can't reach the server
Check sudo ufw status for the Apache rule. Some providers also have a network firewall in front of the server: make sure ports 80 and 443 are open there too. On the server, curl -I http://localhost tells you whether Apache itself answers.
Apache won't start: "Address already in use"
Another program, often Nginx, already uses port 80. Find it with:
sudo ss -ltnp | grep ':80 '
Stop and disable that program, or move it to another port, then start Apache again.
Warning: "Could not reliably determine the server's fully qualified domain name"
This is only a warning. To remove it, tell Apache the server's name and reload:
echo "ServerName server.example.com" | sudo tee /etc/apache2/conf-available/servername.conf
sudo a2enconf servername
sudo apache2ctl configtest && sudo systemctl reload apache2
Related articles
- Host several websites on one server with Apache
- Install phpMyAdmin on Ubuntu
- Connect to your server with SSH
- Change the hostname of a Linux server
Still stuck? Open a support ticket and we'll help.