Create an Apache Virtual Host for a Drupal 9 Site

Create a Drupal site directory. For this setup, websites are at /var/www/
cd /var/www
mkdir example.com

Create .conf files in Apache
cd /etc/apache2/sites-available
nano example.com.conf

Write the following in example.com.conf and save it.

<VirtualHost *:80>
    DocumentRoot /var/www/example.com
    ServerName example.com
    ServerAlias www.example.com
    <Directory "/var/www/example.com/">
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
        RewriteEngine on
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} !=/favicon.ico
        RewriteRule ^ index.php [L]
    </Directory>
    ErrorLog /var/log/apache2/example.com-error_log
    CustomLog /var/log/apache2/example.com-access_log common
</VirtualHost>

Copy example.com.conf to /etc/apache2/sites-enabled folder.
cp example.com.conf ../sites-enabled/

Enable the new virtual host
a2ensite example.com.conf

Restart webserver
service apache2 reload

Category

Comments