How to add new domains on ubuntu apache server

June 22, 2020

To add new domains in your ubuntu server but not in the public folder (/var/www/html), you can follow these steps:

First, create the folder for the new website, and give the ownership to user www-data that will run the webpages:

sudo mkdir /var/www/

sudo chown -R www-data:
www-data /var/www/

Then add these lines in the file /etc/apache2/sites-available/000-default.conf or in anew file(

ServerAlias * # redirect all subdomains
DocumentRoot "/var/www/"

<Directory /var/www/>
Require all granted
AllowOverride All

Enable the new file
sudo a2ensite

For the change to take effect, restart the server

sudo service apache2 restart

For more information, or if you want to add the new virtual hosts with different files, checkout the links: