To set up a virtual host (vhost) under Apache on your Ubuntu server is relatively simple. First you need to create a config file under the /etc/apache2/sites-available directory. A good practice is to name this file the same as the folder you want to use to hold this virtual host’s web pages.
For this example we want to serve up traffic coming in for www.mydomain.com, so we create a file called mydomain:
sudo nano /etc/apache2/sites-available/mydomain
The contents of which looks like this:
allow from all
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
CustomLog /var/log/apache2/mydomain-access.log combined
ErrorDocument 404 /error_documents/404.php
ErrorDocument 403 /error_documents/403.php
With the file saved, next we enable the site by running:
sudo a2ensite mydomain
Finally, reload the Apache configuration with:
sudo /etc/init.d/apache2 reload
(And if you are in the process of looking for a hosting server, you may want to check out different web hosting companies first to help you compare and find the most appropriate hosting account for you.)