Skip to main content
paulk7737514
Inspiring
June 19, 2017
Answered

Switching between virtual host and localhost

  • June 19, 2017
  • 1 reply
  • 3295 views

I created a virtual host by copying and pasting this code in my httpd-vhosts configuration file:

!

##<VirtualHost *:80>

    ##ServerAdmin webmaster@dummy-host.example.com

    ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"

    ##ServerName dummy-host.example.com

    ##ServerAlias www.dummy-host.example.com

    ##ErrorLog "logs/dummy-host.example.com-error.log"

    ##CustomLog "logs/dummy-host.example.com-access.log" common

##</VirtualHost>

If I delete this code I won't be able to access the site for which I created the fake domain. On the other hand, I can't create another site because now 127.0.0.1 is synonymous with the virtual domain.

So do you keep the changed code and comment it out until the day you might need to access the site? Or do you change the site host name to localhost/sitename as you would normally when you create a site to test locally?

    This topic has been closed for replies.
    Correct answer Rob Hecker2

    I usually just put the site folder name after the localhost/ so I don't have to do anything.

    http://localhost/vehiclemanager

    http://vehiclemanager.com


    I usually just put the site folder name after the localhost/ so I don't have to do anything.

    Sure. I think many people do that,  but it won't be as close a match to the remote system as if you used virtual hosts. I never use an extension (com net org) when I create virtual hosts, but if I have two sites with the same name but different extensions, I use:

    china_com
    china_net

    1 reply

    Rob Hecker2
    Legend
    June 19, 2017

    I have about 20 virtual hosts pointed to 127.0.0.1

    In windows / system32  / drivers / hosts you attach all of them to 127.0.0.1 but in Apache you point each domain to the specific "physical location" in the file path

    Example:

    <VirtualHost *:80>

        DocumentRoot "D:/Apache24/htdocs/yogasite/55"
        <Directory "D:/Apache24/htdocs/yogasite/55">
            Options +Indexes +FollowSymLinks +ExecCGI
            DirectoryIndex index.php
            Order allow,deny
            Allow from all
            AllowOverride All
            Require all granted
        </Directory>

        ServerName china:80
        SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
       
        # include the folder containing the vhost aliases for zend server deployment
        IncludeOptional "D:\ZendServer\etc\sites.d\http\china\80/*.conf"

    </VirtualHost>

    paulk7737514
    Inspiring
    June 19, 2017

    Hi Rob. For some reason it stripped out my code in the previous post.

    The code I added my virtual domain information is

    ##<VirtualHost *:80>

        ##ServerAdmin webmaster@dummy-host.example.com

        ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"

        ##ServerName dummy-host.example.com

        ##ServerAlias www.dummy-host.example.com

        ##ErrorLog "logs/dummy-host.example.com-error.log"

        ##CustomLog "logs/dummy-host.example.com-access.log" common

    ##</VirtualHost>

    Rob Hecker2
    Legend
    June 20, 2017

    That is the example code from Apache 2.4. Assuming that you are replacing dummy-host with your domain name and removing the comment characters, that is correct code. The most important lines are the DocumentRoot and ServerName.