How to Create a Symbolic Link in Windows
On my Linux server, I use symbolic links all the time to make shortcuts for myself (if you need to know how, this tutorial from Indiana University can help). I recently istalled XAMPP on my Windows machine and wanted to use a shortcut so that I could access my PHP scripts from my browser. I figured out how to, but from several different sources, so I thought I would consolidate. Here are the steps:
- Click the Start Button.
- Type cmd in the search box at the bottom.
- Press the Ctrl + Shift + Enter keys all at once.
Note: This opens up the command prompt as Administrator. If you don't do this, you'll get a error saying that there are insufficient permissions to create the symbolic link later on. You can also right click and select "Run as Administrator" to accomplish the same thing.
- A box saying "Windows needs your permission to continue" will pop up. Click Continue.
- Go to the directory you want to create the link in. For example:
- Use mklink to create your symbolic link (or shortcut):
mklink /D symfolder "c:\Users\username\Documents\My Folder\"Note: The /D is there because, in this example, we are linking to a directory. symfolder is the name of our symbolic link, you can change that to whatever you want. And, we have quotes around the target because there is a space in the name of it – if there's a space, you have to use the quotes, otherwise you'll get an error. To see more info about mklink, simply type mklink into the command prompt and then press Enter. A help dialogue will appear.
That's it! Your symbolic link has now been created.
If you were doing this in order to run a PHP script locally, here's how… Let's assume that your filename was c:\Users\username\Documents\My Folder\hello-world.php for this example. All you have to do is open up your browser and type http://localhost/symfolder/hello-world.php into the navigation bar. XAMPP is looking for files in the c:\xampp\htdocs\ folder and you told your system that symfolder should actually point to My Folder, so the hello-world.php script is found.
This post was first published on April 22nd, 2011 and last updated on October 22nd, 2014 by Robert James Reese in the following categories: Command Prompt, PHP, Windows, and XAMPP. Before using any of the code or other content in this post, you must read and agree to our Terms & Conditions.