Setting up Virtual Hosts on Ubuntu
For the most part, I utilize AWS-EC2 to build one site per instance. Even subdomains are usually kept on separate instances. However, lately, I got a project where I would be setting up an instance and adding several different micro sites to one instance, and using a shared database. So, I figure I would need to setup some virtual hosts, which I had not done up to this point. What I found, was that this was very easy. Here’s how!
First thing to do is get into the directory that controls all this stuff.
cd /etc/apache2/sites-available
Next enter this information into a file you create for your domain. So first I would enter
sudo pico mydomain.com
And they I would enter this information into the file and save it.
<VirtualHost *:80>
DocumentRoot {DIRECTORY}
ServerName {DOMAIN_NAME}
ServerAlias {DOMAIN_NAME_WITHOUT_WWW}
# Other directives here
</VirtualHost>
Now you need to load it up into apache by running this.
sudo a2ensite mydomain.com
And finally reload apache.
sudo /etc/init.d/apache2 reload
Other links and information:
thinkingnectar.com
tips-linux.net
