Apache Virtual Hosts in Ubuntu

By | July 4, 2012

We are going to create 3 sites, site1.com, site2.com and site3.com

1. Create the folders that will host your new sites. By default, Apache in Ubuntu serves from /var/www. So create these:

mkdir /var/www/site1
mkdir /var/www/site2
mkdir /var/www/site3

2. Copy the current default setting found in /etc/apache2/sites-available/default and name it the same as your new site.

cp /etc/apache2/sites-available/default /etc/apache2/sites-available/site1
cp /etc/apache2/sites-available/default /etc/apache2/sites-available/site2
cp /etc/apache2/sites-available/default /etc/apache2/sites-available/site3

3. Edit the new config files for each site using your preferred text editor. Add the line ServerName server1 right below the ServerAdmin line and change both DocumentRoot and Directory to point to your new sites.

/etc/apache2/sites-available/site1


	ServerAdmin webmaster@localhost
	ServerName site1

	DocumentRoot /var/www/site1
	
		Options FollowSymLinks
		AllowOverride All
	
	
		Options -Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
	

	ErrorLog ${APACHE_LOG_DIR}/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog ${APACHE_LOG_DIR}/access.log combined

4. After you have edited the config files for each of the 3 or how many virtual hosts you are creating, just tell Apache to start serving the new domains and stop serving the default:

sudo a2ensite site1
sudo a2ensite site2
sudo a2ensite site3
sudo a2dissite default

5. Now reload apache and you should be able to get to each of your new domains:

sudo /etc/init.d/apache2 reload

Credit:http://www.fospre.com/apache-virtual-host-ubuntu/

Loading