Last month I got a chance to play with an Ubuntu Linux server to set up Virtual Hosting for couple of sites in the office. Most of the time this is achieved through cPanel interface, this server was not supported with GUI tools but I got the root access .
Unfortunately I had only heard and read little about Virtual Hosting. So this was sort of a challenge for me. So first of all I did a bit of searching to get to know the basics of Virtual Hosting. With couple of hours effort I managed to figure out what should be done.
Following is the folder structure I created in the server to hold the site related resources. Sometimes I might have missed some of the important aspect, so strongly recommends you to refer here for a complete explanation.
- html – place all the resources required for the site.
- logs – place the access log and error log files.
- etc – place other resources that are not directly required for the site but you feel like useful for future activities.
Once above is completed next step is to update the apache server about the new Virtual Host. Following block illustrates the necessary configuration for the new Virtual Host. Opens up your favorite text editor and place the below content block and replace the ‘yoursite.com‘ with the sites actual name. Save the file as yoursite.com in the following path: /etc/apache2/sites-available/ and create a symbolic link to /etc/apache2/sites-enabled/.
- Opens the terminal window
- Creates a new file having a name like ‘yoursite.com‘ (replace this with your actual site details) using vim editor: sudo vim /etc/apache2/sites-available/yoursite.com
- Enter into insert mode by pressing i key on your keyboard and place the below code block and replace respective location to reflect to your site’s settings.
- Next click Esc key on your keyboard and type :wq
- Finally create a symbolic link to /etc/apache2/sites-enabled/ using following command: ln -s /etc/apache2/sites-available/yoursite.com /etc/apache2/sites-enabled/yoursite.com