Question

I'm using XAMPP on my Windows 7 computer when doing web projects. In my httpd.conf file, DocumentRoot is set up simple, like this:

DocumentRoot "D:/Users/Thinkpad/DropBox/MAMP"
<Directory "D:/Users/Thinkpad/DropBox/MAMP">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
</Directory>

This location is used for work projects, and now I want a separate location just like this one, for private projects. Just have it to point to a different localpath, D:/Users/Thinkpad/DropBox/Web, and preferrably name it something other than localhost. Something like private or something. So my URL will end up looking like this http://private/mywebproject

I've tried looking at documentation for this, but I can't get it to work. Do I need to edit my hosts file for it to work? And what else needs to be set in httpd.conf file?

Edit: So here's the final solution from the httpd-vhosts file

<VirtualHost private:80>
    DocumentRoot "D:/Users/Thinkpad/Dropbox/Web"
    ServerName private
    ErrorLog "logs/dropbox.local-error.log"
    CustomLog "logs/dropbox.local-access.log" combined
    <Directory "D:/Users/Thinkpad/Dropbox/Web">
        AllowOverride All
        Order Allow,Deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost localhost:80>
    DocumentRoot "D:/Users/Thinkpad/Dropbox/MAMP"
    ServerName private
    ErrorLog "logs/dropbox.local-error.log"
    CustomLog "logs/dropbox.local-access.log" combined
    <Directory "D:/Users/Thinkpad/Dropbox/MAMP">
        AllowOverride All
        Order Allow,Deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

I had to add the regular localhost as well, even though it was already defined in httpd.conf file.

Also, hosts-file needed to have these two lines:

127.0.0.1           localhost
127.0.0.1       private
Was it helpful?

Solution

You have to add new virtual host by default in C:\xampp\apache\conf\extra\httpd-vhosts.conf add something like

 <VirtualHost *:80>
 ServerName      private.localhost
 DocumentRoot    D:/Users/Thinkpad/DropBox/private
 </VirtualHost>

and after that you have to edit windows hosts file

append this

127.0.0.1       private.localhost

then restart the xammp

You may take a look to one project that makes this easy https://github.com/vkdimitrov/VhostsEditor

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top