In my previous post, I showed you how to install a LAMP (Linux, Apache, MySQL, PHP) stack on Ubuntu 11.10. In this post, I will guide you through the process of configuring virtual hosts. This will allow you to create multiple independent websites, even across different domains.
Setting up the Directory Structure
First, decide where you want to store the folder that will contain your website files. In my case, I have a large ‘/home’ partition, so I chose to create a folder at ‘/home/www’.
Creating a Virtual Host Configuration
Now, let’s create a new virtual host configuration file.
Edit the ‘example’ file and paste the following code into it:
Save the file and run the following commands to create the necessary directory structure and enable the virtual host:
Configuring Local DNS Resolution
To access your website, you can either configure your DNS to resolve the URL ‘http://example.localhost’, or you can simplify things by adding an entry to your ‘/etc/hosts’ file.
Add the following line to the file:
Save the file and try opening the URL ‘http://example.localhost’ in your web browser.
You can check for any site errors and warnings by inspecting the log file located at ‘/home/www/log/error.log’.