How to make a virtualhost (another folder like htdocs)

Was in a awkward situation! Nomally I use my desktop computer and its a pain when I need files from laptop, I started using dropbox for file sharing but it’s not possible to sync my localhost folder via dropbox. Got a solution by adding a virtualhost (a new folder which will act like htdocs) which will stay in dropbox. Pretty easier way to share codes.

1. Open the file with notepad or any text editor.

 C:\xampp\apache\conf\extra\httpd-vhosts.conf

2. Copy and paste below codes at the end of the file.

<VirtualHost *:80>
  ServerAdmin info@asifsaho.me
  DocumentRoot "D:/Dropbox/Project"
  ServerName projects.me
  ServerAlias www.projects.me
  ErrorLog "logs/projects.me-error.log"
  CustomLog "logs/projects.me-access.log" combined
<Directory "D:/Dropbox/Project">
  Options Indexes FollowSymLinks Includes ExecCGI
  AllowOverride All
  Order allow,deny
  Allow from all
  Require all granted
</Directory>
</VirtualHost>

– Change the DocumentRoot value with your folder link which is standing in dropbox.

– Change the ServerName to the address (without www.) which should be used to open the folder (like: localhost)

– ServerAlias should be same as ServerName but with “www.”

– Also you can edit ErrorLog and CustomLog format if you wish.

 

Now open the hostfile (C:\Windows\System32\Drivers\etc) and add a line like below (change the address as your need).

127.0.0.1 www.projects.me projects.me

NB: You may not save the hostfile directly, you can copy it to desktop then replace the old file.

Here is a tutorial about troubleshooting, don’t forget to review if get any problem.