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

More Apache tasks

Back to the full Apache cheat sheet