Apache2 Server
Installing and configuring an Apache2 web server on Ubuntu to serve content from the /var/www/
directory (the default web root).
1. Update System Packages
sudo apt update
sudo apt upgrade -y
2. Install Apache2
sudo apt install apache2 -y
Apache will automatically start after installation.
3. Verify Apache2 is Running
sudo systemctl status apache2
You should see active (running)
. If not, start it:
sudo systemctl start apache2
4. Allow HTTP Through Firewall (Optional but Recommended)
If you're using UFW (Uncomplicated Firewall):
sudo ufw allow 'Apache'
sudo ufw enable
To check the status:
sudo ufw status
5. Check Apache Default Page in Browser
Open a browser on the same machine or from another PC on the same network:
http://<server-ip>
You should see the "Apache2 Ubuntu Default Page."
To find your server’s IP address:
ip a
Option 1: Open Nautilus with Root Permissions
Open Terminal.
Run:
sudo nautilus /var/www/
A new Nautilus window with root access will open.
Now you can drag and drop or create files and folders inside
/var/www/
.
Option 2: Use a Custom Directory (Safer)
If you want to avoid using root access frequently, it’s safer to:
- Create a folder inside your home directory:
mkdir ~/myweb
Move your files there via Nautilus normally.
Then change Apache’s default web root to this new folder (optional).
Edit Apache's default site configuration:
sudo nano /etc/apache2/sites-available/000-default.conf
- Modify the
DocumentRoot
line:
DocumentRoot /home/yourusername/myweb
sudo systemctl restart apache2
- Visit
http://localhost
to see your custom content.
Apache Folder Structure Basics
Folder | Purpose |
---|---|
/var/www/ | Default document root |
/etc/apache2/sites-available/ | Virtual host config files |
/etc/apache2/apache2.conf | Main config file |
/etc/apache2/ports.conf | Port settings |
/var/log/apache2/ | Apache logs |