Windows – Using symbolic link directories with Apache, PHP and Windows 7

apache-http-serverPHPsymbolic-linkwindows 7

I am trying to setup a symbolic link for a directory and I am getting the strangest error. I am using:

mklink /d C:\www\site\inc C:\inc

where C:\inc\script.php is the file I need to run. This seems simple enough, and it does work the first time I execute the script (by accessing http://localhost/inc/script.php). After that however, I get an error and cannot get the script to execute successfully again until I delete and recreate the symbolic link (even shutting down Apache or restarting Windows has no effect).

Note that everything else is running normally, the symbolic link does work, and Apache does have permission to access C:\inc and also has FollowSymLinks enabled. Here is the error I am getting:

Warning: Unknown: failed to open
stream: No such file or directory in
Unknown on line 0

Fatal error: Unknown: Failed opening
required 'C:/inc/script.php'
(include_path='.;C:\php5\pear') in
Unknown on line 0

Does anyone know what the deal is with the Unknown on line 0, and why would it execute exactly one time before giving this error?

Best Answer

Why not just use Alias in Apache to achieve what you want rather than using NTFS SymLinks?

Put this in your httpd.conf:

Alias /inc "C:/inc"

<Directory "C:/inc">
    Options Indexes FollowSymLinks
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>
Related Question