set up a
virtual host
with Apache
on Ubuntu Linux

Navigate to the Apache configuration files directory.

cd /etc/apache2/sites-available

There are two default configuration files in there.

ls
000-default.conf default-ssl.conf

Use the default file as a template for your configuration file. Name it after your website.

cp 000-default.conf anarchitecture.io.conf

Then open it with your favorite in terminal text editor. The most popular tend to be vi or nano.

sudo nano anarchitecture.io.conf

Change the ServerAdmin to an email address that you check, the ServerName to your domain, the ServerAlias to "www." + your domain, and DocumentRoot to the location of the folder you created earlier in /var/www for the website.

<VirtualHost *:80>
    ServerAdmin anarchitect@anarchitecture.io
    ServerName anarchitecture.io
    ServerAlias www.anarchitecture.io
    DocumentRoot /var/www/anarchitecture.io
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and exit the file, then run the a2ensite command to activate the configuration file, which is part of Apache.

sudo a2ensite anarchitecture.io.conf

Make sure to deactivate the default configuration file too.

sudo a2dissite 000-default.conf

Then test for any configuration errors.

sudo apache2ctl configtest

If the test returns Syntax OK, then you're good.

sudo systemctl restart apache2

Restart Apache to apply any changes.

NEXT =
domain name →