Setup several domain names on one VPS

How to setup several domain names on one server, or VPS.

First we create the folder of the respective website domain name :

sudo mkdir -p /var/www/example.com/public_html

Then we grant the permissions :

sudo chown -R $USER:$USER /var/www/example.com/public_html

To allow everyone to see it :

sudo chmod -R 755 /var/www

We create an index page :

sudo nano /var/www/example.com/public_html/index.html

Here is what we put inside the index.html :


  
    www.example.com
  
  
    

Success: You Have Set Up a Virtual Host

Then we create the virtual host file :

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/example.com

We open the config file :

sudo nano /etc/apache2/sites-available/example.com

We set the following lines :

ServerName example.com

        ServerAdmin webmaster@example.com
        ServerName example.com
        ServerAlias www.example.com
  [...]
DocumentRoot /var/www/example.com/public_html

We save and exit (Ctrl+O, Ctrl+X).

Finally, we activate the host :

sudo a2ensite example.com

We restart Apache :

sudo service apache2 restart