Saturday, August 15, 2015

Create Symbolic Link to 'www' folder (Windows)

Saving and updating each and every files and folders in the 'www' folder to our preferred cloud service is great, isn't it? So that we don't need to manually backup our local projects. My preferred cloud service is google drive and it has an app for windows pc. After installing the app you will get a Google Drive folder in your pc. The working is simple, it's two way syncing: whatever files and folders you add to the google drive folder in your pc gets uploaded and updated in your online google drive account and whatever files and folders you add to the online google drive account gets downloaded and updated in your pc.
I am using wamp in Windows 7 for web development projects. The working directory for web projects in my case is C:/Program files/wamp/www/. I want the www folder to get synced with Google drive. So what I did was moved the 'www' folder and its contents to the C:/Users/sreenath/Google Drive/www and made a symbolic link to this www folder in C:/Program files/wamp/
. So now I have a symbolic link of C:/Users/sreenath/Google Drive/www at C:/Program files/wamp/www. The link will act like normal folder except that every modifications we make are being committed in the C:/Users/sreenath/Google Drive/www and since it's in Google Drive folder everything gets uploaded instantly.
So What Are Symbolic Links?
Symbolic links, otherwise known as symlinks, are basically advanced shortcuts. You can create symbolic links to individual files or folders, and then these will appear like they are stored in the folder with the symbolic link even though the symbolic link only points to their real location.

How to create Symbolic Links?
We can create symlinks using the command mklink in windows 10/8/7. Run command prompt as administrator. Enter 'command' in the start menu search, right click on Command Prompt and select 'Run as administrator'.
Now you need to run this command:

mklink /J "C:/Program files/wamp/www" "C:/Users/sreenath/Google Drive/www"

/J says mklink to create a directory junction.
If everything went well you will be having a link folder 'www' in C:/Program files/wamp which acts exactly like C:/Users/sreenath/Google Drive/www. Now you can make new folders, new files, delete folders, files anything in C:/Program files/wamp/www.
One more thing is there to do. Since the actual www folder is in Google Drive, apache cannot access it because of permission issues. So we give full permission to this folder so that apache can access it.
It can be done like this: Open command prompt as administrator just like we did before and run the following command:

icacls "C:/Users/sreenath/Google Drive" /grant Everyone:(OI)(CI)F. 

Now if you point the browser to localhost you will see all your projects.
The best part of this is that if you have a laptop with Google Drive installed and logged in and do the above steps in it, the exact www folder of the pc is available in your laptop. If you make changes in laptop it will instantly get modified in the pc once synced!