sudo mkdir /var/www/your_domain
Now we will set permissions on the directory with the $USER environment variable, which should refer to your current system user:sudo chown -R $USER:$USER /var/www/your_domain
Open a new configuration file under Apache's sites-available directory using a command line editor. In our example, we are using nano:sudo nano /etc/apache2/sites-available/your_domain.conf
Paste the following settings:<VirtualHost *:80> ServerName your_domain ServerAlias www.your_domain ServerAdmin webmaster@localhost DocumentRoot /var/www/your_domain ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
With these VirtualHost settings, we are essentially telling Apache to serve the content of your domain in the following directory:/var/www/your_domain
You can test Apache without a domain name by removing the ServerName and ServerAlias options or by adding a # at the beginning of each option's line. Now you can use a2ensite to activate this virtual host:sudo a2ensite your_domain
For convenience and security reasons, it is recommended to disable the default website that comes with Apache. To disable the default Apache website, type:sudo a2dissite 000-default
To ensure that your configuration file does not contain any syntax errors, you can run:sudo apache2ctl configtest
Finally, reload Apache for the changes to take effect:sudo systemctl reload apache2
Your new site is active, but its root directory—/var/www/your_domain—is empty.