简体   繁体   中英

Creating a symbolic link in Sites directory to a file in another directory

This question addresses how to enable symbolic links in the Sites directory; however, it only works on directories.

With FollowSymLinks , Apache on OS X will follow symlinks for directories, but not for files.

For example:

This works: ~/Sites/Experiments -> /Users/myusername/Projects/Experiments/

This fails: ~/Sites/test.html -> /Users/myusername/Projects/Test1/test.html

Forbidden 
You don't have permission to access

How can I configure Apache or permissions so that Apache will follow file symlinks?

The target file needs to be readable by the Apache user (probably www-data) for it to be served. Directories are different as most users are able to execute on a directory to view the list of files contained regardless of whether they can read the files contain within.

  1. Check that the file permission on the target file and all of it's parent directories are accessible by your webserver user (probably www-data). World-readable permission is good enough. If you don't care about security all that terribly much (meaning that this isn't a production system), you can just do something like this: chmod o+rx /Users/myusername/Projects /Users/myusername/Projects/Test1; chmod o+r /Users/myusername/Projects/Test1/test.html chmod o+rx /Users/myusername/Projects /Users/myusername/Projects/Test1; chmod o+r /Users/myusername/Projects/Test1/test.html
  2. Be sure that you don't have any <Location> or <Directory> blocks that are forbidding that target directory from working.
  3. Be sure that you do have a <Directory> block that allows access to your /Users/myusername/Projects/Test1 path. Typically Apache will only grant that access to a default location which doesn't include your home directory. You can do this by temporarily adding in the following (remove it after you've fixed the permissions problem, otherwise it's offering too much access):

-

# This is a temporary debugging tool, don't leave it forever.
<Directory "/">
  Options Indexes FollowSymLinks
  AllowOverride All
  Order allow,deny
  allow from all
</Directory>

尝试使用chmodchgrp (在最坏的情况下,使用chown )来设置适当的权限,以至少由Apache Web服务器读取和执行文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM