Setting up your own web server is actually quite straightforward with Apache on Ubuntu. In this case I use a simple HTML as website for this guide that walk you through the entire process step by step. The goal is to setup the website that allow visiting in the local network.
Prerequisites
Before we begin, make sure you have:
- An Ubuntu system (this guide works for Ubuntu 24.04 )
- SSH ready. (If you want to know how to setup SSH on Ubuntu, check this post.)
- Terminal access with sudo privileges
- Basic familiarity with command line operations
1. Install a Web Server (Apache)
The first step is installing Apache.
sudo apt update sudo apt install apache2
The apt update
command refreshes your system's package list to ensure you're installing the latest version. The apt install apache2
command downloads and installs Apache along with all its dependencies.
Once installation completes, Apache should start automatically. Let's verify it's running properly:
sudo systemctl status apache2
You should see output indicating the service is active (running)
with a green status indicator.
2. Place Your Website Files
Now that Apache is running, it looks for website files in a specific location called the web root directory. On Ubuntu, this directory is /var/www/html/
.
Since this directory requires administrator privileges to modify, you'll need to use sudo
for any file operations:
sudo nano /var/www/html/index.html
Here's a simple HTML template you can use to get started:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Local Web Server</title> </head> <body> <h1>Welcome to My Apache Server!</h1> <p>If you can see this page, your Apache web server is working correctly.</p> </body> </html>
After pasting your content, save the file by pressing Ctrl+X
, then Y
to confirm, and Enter
to finalize. You can add additional files like CSS stylesheets, images, or JavaScript files to the same directory – Apache will serve them all.
3. Configure the Firewall
Ubuntu's built-in firewall (UFW - Uncomplicated Firewall) is designed to block unauthorized network traffic by default. This is great for security, but it also blocks legitimate web traffic. We need to create a specific rule to allow web browsers to connect to your Apache server.
sudo ufw allow 'Apache'
Let's verify the firewall rule was added correctly:
sudo ufw status
You should see an entry showing that Apache traffic is allowed.
4. Find Your Server's IP Address
To access your website from other devices on your network, you need to know your server's IP address.
ip addr show
This command displays all network interfaces on your system. Look for the main network interface – it's usually named something like enp0s3
, eth0
, or wlan0
(for wireless connections). Under this interface, you'll find a line that starts with inet
followed by an IP address.
The IP address you're looking for will be in one of these ranges:
192.168.x.x
(most common for home networks)10.x.x.x
(often used in corporate networks)172.16.x.x
to172.31.x.x
(less common but valid)
Copy this IP address. This is your server's local IP address, meaning it's only accessible from devices on the same network (like your home Wi-Fi network).
5. Visit Your Website
Open a web browser on any device connected to the same network as your server.
In the browser's address bar, past your server's IP address with the http://
prefix:
http://<your-server-ip>
For example, if your server's IP address is 192.168.1.100
, you would type:
http://192.168.1.100
If everything is configured correctly, you should see your index.html
page displayed in the browser.
Troubleshooting
Even following the steps carefully, you might encounter some issues. Here are the most common problems and their solutions, organized by symptoms to help you quickly identify what's wrong.
Case 1: Apache Fails to Start (Port 80 In Use)
Symptom: When you run sudo systemctl status apache2
, you see a failed
status. The error logs mention "Address already in use" or "could not bind to address [::]:80".
Cause: Another web server or application is already using port 80. This commonly happens if you have Nginx installed or if you're running other development servers.
Solution: Identify and stop the conflicting service:
# Find what program is using port 80 sudo lsof -i :80 # If it's nginx, stop and disable it sudo systemctl stop nginx sudo systemctl disable nginx # Then start Apache again sudo systemctl start apache2
The lsof
command lists all open files and network connections. The -i :80
flag specifically looks for processes using port 80. Once you identify the conflicting program, you can stop it and start Apache.
Case 2: "This site can't be reached" (ERR_ADDRESS_UNREACHABLE)
Symptom: Your browser displays an error message saying it can't connect to the server, or you get a "connection refused" error.
Cause: This indicates a network connectivity or firewall issue preventing your browser from reaching the Apache server.
Solution: Debug systematically by checking these three things in order:
-
Is Apache actually running?
sudo systemctl status apache2
If it's not running, start it with
sudo systemctl start apache2
. -
Is the firewall blocking connections?
sudo ufw status
You should see an
ALLOW
rule for Apache or port 80. If not, run the firewall configuration step again. -
Can your client reach the server at all?
ping <your-server-ip> # Or curl -v http://<your-server-ip>
Run this from the computer where you're trying to browse the website. If ping fails, you have a network connectivity issue – make sure both devices are on the same network and can communicate with each other.
Next Steps
Your Apache web server is now ready to serve websites to your local network. Whether you're developing the next big web application or just learning how the web works, you now have a startpoint to build upon.