mkdir /home/UserA/htdocs
sudo chown -R UserA:UserA /home/UserA/htdocs
sudo chmod -R 755 /home/UserA/htdocs
Next we'll create a test page for our virtual host.
echo 'Test Site' > /home/UserA/htdocs/index.html
Now we are going to start with a sane configuration for our new virtual host.
cd /etc/apache2/sites-available
sudo cp 000-default.conf 001-UserA.conf
We need to edit our base configuration for our purposes.
sudo nano 001-UserA.conf
In the file that opens change the ServerAdmin to your own email address DocumentRoot to our document root and add ServerName and set that to the name of the website
ServerAdmin admin@UserA.com
DocumentRoot /home/UserA/htdocs
ServerName UserA
We also want to set the different log files for our hosts so change the ErrorLog and CustomLog to read something like this:
ErrorLog ${APACHE_LOG_DIR}/UserA.error.log
CustomLog ${APACHE_LOG_DIR}/UserA.access.log combined
Lastly we want give Apache permission to access our folder. If you forget to add these lines you will receive a 403 Forbidden error when you try to access your website. Add these lines right after the log configurations:
<Directory /home/UserA/htdocs
Require all granted
</Directory>
Save and exit the file (Ctrl+X). Now in enable the virtual host
sudo a2ensite 001-UserA.conf
Check if there are any errors in the newly added configuration files
apachectl configtest
If you see a Syntax OK message then we have configured Apache correctly and are ready to reload the configuration
sudo service apache2 reload
Optionally you may want to edit your /etc/hosts file and add the new hostname there
sudo nano /etc/hosts
Add the following lines at the bottom of the file
127.0.0.1 UserA.com
Now open your a browser and visit your virtual host site .