Apache – Setup the VirtualHost

Usually, people got more than one website in the Apache web server and sometimes they want to separate them into different domain names. This can be done by the Apache VirtualHost.

The following example is done in Mac MAMP, i guess the configuration on Linux and Windows should be similar. Let’s start now.

1. I have 2 folders in the Apache webroot folder

  • drupal-6.19 – The Drupal Application
  • HelloWorld – Folder contains simple HTML


 

2. I am going to set the following domain names for them

  • drupal-6.19 – drupal.ykyuen.wordpress.com
  • HelloWorld – test.ykyuen.wordpress.com

 

3. Edit the /etc/hosts as follow

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost

# Newly added domain name
127.0.0.1       drupal.ykyuen.wordpress.com
127.0.0.1       test.ykyuen.wordpress.com

 

4. Create the following 2 files in the /Applications/MAMP/conf/apache
drupal-6.19.conf

<VirtualHost *:8888>
	ServerName drupal.ykyuen.wordpress.com
	DocumentRoot /Applications/MAMP/htdocs/drupal-6.19/
	<Directory /Applications/MAMP/htdocs/drupal-6.19/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		Allow from all
		# Rewrite settings for Drupal clean urls
		RewriteEngine on
		RewriteBase /drupal-6.19
		RewriteCond %{REQUEST_FILENAME} !-f
		RewriteCond %{REQUEST_FILENAME} !-d
		RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
	</Directory>
</VirtualHost>

 

HelloWorld.conf

<VirtualHost *:8888>
	ServerName test.ykyuen.wordpress.com
	DocumentRoot /Applications/MAMP/htdocs/HelloWorld/
	<Directory /Applications/MAMP/htdocs/HelloWorld/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>

 

5. Append the following lines to /Applications/MAMP/conf/apache/httpd.conf

NameVirtualHost *:8888
Include /Applications/MAMP/conf/apache/drupal-6.19.conf
Include /Applications/MAMP/conf/apache/HelloWorld.conf

 

6. Restart the Apache Server

7. Test the 2 new domain name with your browser.

 

Done =)

Reference: How to set up virtual hosts in the MAMP environment

2 thoughts on “Apache – Setup the VirtualHost”

Leave a reply to ykyuen Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.