Home > Guides, Web Development > PHP 5.3 symlink() in Windows Vista and Server 2008

PHP 5.3 symlink() in Windows Vista and Server 2008

June 17th, 2009

I just discovered that Vista can create symbolic links via the command mklink! It performs the same thing as ln in linux with both hard and soft links. My understanding of links is fairly limited but I use them on my web server to apply seam-less templates. Until now, this was something that I could only test on my web server and not my Windows 7 development PC. PHP 5.3 automatically uses the mklink command when you use symlink() but the problem comes with enabling it in Windows Vista or 7.

If you pull up a command prompt and try to use mklink, you’ll see something like this:

D:\Web>mklink /D nnnnn.com\content templates\bluemoon
You do not have sufficient privilege to perform this operation.

Or PHP will throw this back at you:

Debug Warning: /includes/templates.inc.php line 78 - symlink() [function.symlink]: Cannot create symlink, error code(1314)

To fix this:

  1. Bring up your run box, type “secpol.msc” and click OK.
  2. Navigate under the Security Settings \ Local Policies \ User Rights Assignment folder.
  3. Find “Create symbolic links” and add the Users group to it.

I think you need to restart your computer or something after doing this.

Josh Guides, Web Development , , , , , ,

  1. October 1st, 2009 at 21:16 | #1

    This might be a bug within php as exec(”mklink /j target link”) would work without having to change anything, please note that /j may not be the switch you need but a mklink /? would show you one that might.

    I used it to make one and was unable to fopen any files from behind the system link, but if_file() returned true.

  2. November 12th, 2009 at 02:10 | #2

    Another possibility is to run PHP or your IDE as administrator. For example, with Zend Studio for Eclipse, you can right-click and say “run as administrator”. Obviously you only want to do this if you’re careful… and ALWAYS… only do this on a testing environment with code you’re familiar with.

    Typically, I have to use symlink very sparingly… and on windows… I only do this as part of the local development process prior to uploading it to my staging server.

  1. June 17th, 2009 at 12:40 | #1
  2. June 18th, 2009 at 03:55 | #2
Comments are closed.