Configuring Virtual Hosts in XAMPP on Mac OS X

Configuring virtual hosts in xampp on mac is not an easy task.  It has some extra work to do as compared to windows or linux. Here is all the steps to configure it on mac.

STEP 1: open terminal and type

            vim /etc/hosts

It will open hosts file in vim editor (of course you can choose nano or others). press  i  and it will be in insert mode. Then add your host entry such as

127.0.0.1         localhost
127.0.0.1         localhost.zend.com

STEP 2:   Now you need to open

/Applications/XAMPP/xamppfiles/etc/httpd.conf 

(xampp installation path) either in vim or in normal editor via finder (file system in mac). Now you have to find this line

# Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

and need to remove # from starting i.e. uncomment it. save and close this file.

STEP 3: Now you need to open file
/Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf 

and need to add set up your directory and host relation but before that make sure this line

NameVirtualHost *:80

is added before you add your settings. Like this-

NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin webmaster@localhost.com
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
    ServerName  localhost
    ServerAlias www.localhost.com
    ErrorLog "logs/localhost-error_log"
    CustomLog "logs/localhost-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost.ci34.com
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/ci34"
    ServerName  localhost.ci34.com
    ServerAlias www.localhost.ci34.com
    ErrorLog "logs/localhost.ci34.com-error_log"
    CustomLog "logs/localhost.ci34.com-access_log" common
</VirtualHost>

STEP 4: You are almost done just need to restart apache from xampp panel. That's it. Your site is now ready to be used as localhost.ci34.com (whatever you added in hosts & httpd-vhosts.conf file).

Post a Comment