How To Add a Virtual Host on Apache2 Under Ubuntu Server?


Today, I decided to move the last domain hosted on Fasthosts shared server (steakovercooked.com) to QuickHostUK.

I have paid a 2 year contract and there is still one year to go with Fasthosts. However, I decided to do it early despite the fact that I will not get any refund from fasthosts. The major reason is the performance (speed). My friends told me it is slow accessing my website in China. The second reason is that hosting on shared server causes troubles if your site has too much traffic. The web hosting company (fasthosts) will suspend your site even you didn’t do anything technically wrong. If your wordpress blog gets too many spams comments, and you allow each time wordpress sending your emails to notify this, then your website is likely to be suspended (it happened to me once). Their excuse was that your blog is vulnerable and may be under attack. In short, there is a ‘fair use’ policy for fasthosts, and this means you can’t get too much traffic or consume too much resources (CPU, harddisk). For web spaces, you can have ‘unlimited’ FTP spaces, but all those files need to be ‘visible’ at your website. That means you can’t use your FTP space as backup. They will delete your files prior to telling you.

OK. So here are the things I do to migrate the server to VPS from share server.

First, you would need to download all your files (around 8GB, takes around 10 hours to download and upload) and upload them to VPS (create a folder for your new website). Second, you would need to backup all the MySQL databases. To re-upload to the database of VPS, you can first upload the backup *.SQL (see this post) and then login to SSH.

1
mysql -hlocalhost -uuser -ppassword
mysql -hlocalhost -uuser -ppassword

And type in command source database.sql to import the database. After this two steps, you would need to configure the Apache2 server if not, you would need to install it first.

1
sudo apt-get install apache2
sudo apt-get install apache2

Now, go to folder /etc/apache2/sites-available and create a file, in my case, steakovercooked.com.conf

1
2
3
4
5
6
7
8
9
10
11
12
<VirtualHost *:80>
  ServerName steakovercooked.com
  ServerAlias www.steakovercooked.com
  ServerAdmin dr@steakovercooked.com
 
  DirectoryIndex index.php
  DocumentRoot /var/www/steakovercooked.com/htdocs
 
  LogLevel warn
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
  ServerName steakovercooked.com
  ServerAlias www.steakovercooked.com
  ServerAdmin [email protected]

  DirectoryIndex index.php
  DocumentRoot /var/www/steakovercooked.com/htdocs

  LogLevel warn
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Now, you can use command sudo a2ensite steakovercooked.com and the apache2 will add extension (conf) automatically after the site name.

Then you will need to restart the apache2 server using sudo service apache2 restart or reload the configuration using sudo /etc/init.d/apache2 reload

Then, you would either modify the ‘Advanced DNS record’ [the A Record] to point the root and www domain to the IP of your VPS (The DNS Propagation Takes Less Than 24 Hours). Alternatively, you can transfer the domains to your VPS company provider (the procedure takes a couple of days).

advanced-dns-a-records How To Add a Virtual Host on Apache2 Under Ubuntu Server? beginner dns linux mysql Virtual Private Server webhosting wordpress

Advanced DNS A Records

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
660 words
Last Post: Bash Script to Check, Repair, Optimise and Backup MySQL database
Next Post: The bitand in Matlab

The Permanent URL is: How To Add a Virtual Host on Apache2 Under Ubuntu Server?

2 Comments

  1. Ink Say

Leave a Reply