Apache virtual hosts allow a single Apache installation to serve multiple websites, each with its own configuration, document root, and domain name. This guide sets up an Apache virtual host on Ubuntu 26.04 LTS.
Tested and valid on:
- Ubuntu 26.04 LTS
Prerequisites
- Ubuntu 26.04 LTS server with Apache installed
- A domain name pointed to your server
- A user with sudo privileges
Step 1 – Create the Document Root
sudo mkdir -p /var/www/example.com/public_html
sudo chown -R $USER:$USER /var/www/example.com/public_html
sudo chmod -R 755 /var/www/example.com
Step 2 – Create a Test Page
nano /var/www/example.com/public_html/index.html
Add some content:
example.com Virtual host working!
Step 3 – Create the Virtual Host File
sudo nano /etc/apache2/sites-available/example.com.conf
Add:
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Step 4 – Enable the Virtual Host
sudo a2ensite example.com.conf
sudo a2dissite 000-default.conf
Step 5 – Test and Reload Apache
sudo apache2ctl configtest
sudo systemctl reload apache2
Step 6 – Verify with curl
curl -H 'Host: example.com' http://your_server_ip
Conclusion
Your Apache virtual host is live on Ubuntu 26.04 LTS. You can repeat this process for every domain you host. Secure the site with Let’s Encrypt SSL using Certbot to enable HTTPS.