Basic Virtual Host in Apache
From the Apache cheat sheet ยท Virtual Hosts ยท verified Jul 2026
Basic Virtual Host
Setting up a basic virtual host
apache
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>๐ Virtual hosts allow multiple sites on one server
๐ Each vhost needs unique ServerName
๐ Enable with a2ensite command
โก Name-based is most common type