Serve more than one site using virtualhosts on mac OSX

Serve more than one site using virtualhosts on mac OSX

There would be a need for this or that reason to serve more than one site from apache. And this is quite possible using configuration inside the apache

First thing first
go to the apache config, by default it should be

/etch/apache2/apache.conf

And search for

#Include /private/etc/apache2/extra/httpd-vhosts.conf

Which, as you can see, is commented. Hence uncomment that by deleting the # infront of it.

The above task will allow us to mess around the httpd-vhosts.conf file that is in the extras directory.

Lets assume we have a site names siteVH which is residing in the directory /www/sitevh
and lets assume we have another site called siteAnother residing in director /www/siteanother

Now the goal is to access those sites independently. So we will create two different virtual hosts for each one and be able to access them independently


    ServerAdmin youreamil@domain.com
    DocumentRoot "/www/siteVH"
    ServerName sitevh.com
    ServerAlias local.site
    ErrorLog "/private/var/log/apache2/sitevh.log"
    CustomLog "/private/var/log/apache2/sitevh.com-access_log" common
    
        AllowOverride All
        Order allow,deny
        Allow from all
        Options Indexes FollowSymLinks
    

And the we will have the same duplicate values for the other one as well.

Then update the /etc/hosts to let know our local “DNS” :) to know what to do

127.0.0.1 sitevh.com siteanother.com

This shall take care of the whole thing.
One more thing, restart apache

sudo apachectl restart
Mount to NSF Server timed out on Vagrant

Failed to Retrieve Share List from Server when connecting unix

Wi-fi connected but no internet mac troubleshooting

Connecting to Vagrant [PuPHPet] MySql from host

How to reload terminal after updating profile file

installing macports

2 Comments
  1. Cem Gencer

    check out https://echo.co/blog/os-x-1010-yosemite-local-development-environment-apache-php-and-mysql-homebrew
    pretty neat way to create unlimited vhosts without vhost.conf / etc/hosts

    1. gullele

      Thank you very much Cem, this is how we will learn new things. Thanks for sharing.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*