简体   繁体   English

在Sites目录中创建符号链接

[英]Creating a symbolic link in Sites directory

I have a file in my ~/Sites directory that works fine when I browse to it through coderama.local/~coderama/index2.php 我在~/Sites目录中有一个文件,当我通过coderama.local/~coderama/index2.php浏览它时工作正常

Now I want to get tricky and move my index2.php file to somewhere else on my system, so I do this by creating a symbolic link. 现在我想变得棘手并将我的index2.php文件移动到我系统上的其他位置,所以我通过创建符号链接来实现这一点。 However, when I try to access coderama.local/~coderama/index2.php I now get the following error. 但是,当我尝试访问coderama.local/~coderama/index2.php我现在收到以下错误。

Any ideas anyone? 任何人的想法?

Thanks! 谢谢!

Forbidden 被禁止

You don't have permission to access /~coderama/index2.php on this server. 您无权访问此服务器上的/~coderama/index2.php。

That's a configurable Apache option. 这是一个可配置的Apache选项。 It appears that by default on Macs (and probably most installations) Apache is configured to not follow symbolic links. 默认情况下,Macs(可能是大多数安装)似乎将Apache配置为不遵循符号链接。 I'm guessing (as others mention above) that it's for security purposes. 我猜测(正如上面提到的那样)它是出于安全目的。

But it can be really convenient at times to enable following of symbolic links, particularly during development of certain kinds of apps. 但是,有时可以非常方便地启用符号链接,特别是在开发某些类型的应用程序时。 What you need to do is 1) change the Apache configuration to allow the following of symbolic links, and then 2) restart Apache. 您需要做的是1)更改Apache配置以允许以下符号链接,然后2)重新启动Apache。

The configuration step is performed as follows: 配置步骤如下:

a) cd /etc/apache2 (this is where Apache's configuration files are by default on a Mac) a)cd / etc / apache2(默认情况下,这是Apache的配置文件在Mac上)

b) you'll see a couple of directories here. b)你会在这里看到几个目录。 One is called users 一个叫做用户

c) cd users c)cd用户

d) ls should reveal a .conf file with your login name ( login .conf) I'm "marvo" so mine is named "marvo.conf" d)ls应该显示一个带有你的登录名的.conf文件( 登录 .conf)我是“marvo”所以我的名字叫“marvo.conf”

e) Edit this file (I use vi) -- but you have to do it using sudo: e)编辑这个文件(我使用vi) - 但你必须使用sudo来做:

sudo vi marvo.conf

f) You'll see something like f)你会看到类似的东西

<Directory "/Users/marvo/Sites/">
    Options Indexes MultiViews 
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

g) Add the "FollowSymLinks" option so that the second line of that .conf file looks like: g)添加“FollowSymLinks”选项,以使该.conf文件的第二行如下所示:

Options Indexes MultiViews FollowSymLinks

(You can find other configuration options out there on the 'net. I found this page: http://httpd.apache.org/docs/2.0/mod/core.html#directory ) (您可以在'net上找到其他配置选项。我找到了这个页面: http//httpd.apache.org/docs/2.0/mod/core.html#directory

h) Save the file. h)保存文件。

Now you have to restart Apache so that it picks up the configuration change. 现在你必须重新启动Apache,以便它获取配置更改。 Googling around a bit, I found that this is most easily done from the command line with the following command: 谷歌搜索了一下,我发现这很容易通过以下命令从命令行完成:

sudo /usr/sbin/apachectl restart

(Found that at http://mcapewell.wordpress.com/2006/09/22/restart-apache-in-mac-os-x/ ) (发现在http://mcapewell.wordpress.com/2006/09/22/restart-apache-in-mac-os-x/

Now that symbolic link should work just fine on your Sites pages. 现在,符号链接应该在您的网站页面上正常工作。

Had the same issue. 有同样的问题。 Unfortunately, Marvo's answer wasn't enough. 不幸的是,Marvo的答案还不够。

The problem lies with the permissions set on every folder in the path, starting from ~/ . 问题在于路径中每个文件夹上设置的权限,从~/开始。 The directories needs the execute flag set to be able to recurse the directory tree. 目录需要设置execute标志才能递归目录树。 So, in my case, I symlinked a theme folder from ~/Dropbox/projects/theme to a wordpress install on ~/Site/wordpress . 所以,就我而言,我将~/Dropbox/projects/theme的主题文件夹符号链接到~/Site/wordpress上的wordpress安装。

The answer was: 答案是:

chmod a+x ~/Dropbox/
chmod a+rx ~/Dropbox/projects

This is an old issue, but if anyone reaches this page, it might be useful. 这是一个老问题,但如果有人到达此页面,它可能会有用。 :) :)

Seems like a security issue (also suggested by Matt) 似乎是一个安全问题(Matt也建议)

http://discussions.apple.com/thread.jspa?threadID=1771399 http://discussions.apple.com/thread.jspa?threadID=1771399

In addition to Marvo's answer. 除了Marvo的回答。 What helped me was to Change the permission on Documents folder: 帮助我的是更改Documents文件夹的权限

cd ~
chmod a+rx Documents/

I don't remember the specific reason why, but it doesn't work. 我不记得具体原因,但它不起作用。 It's a security issue. 这是一个安全问题。 You can use XAMPP http://www.apachefriends.org/en/xampp-macosx.html or MAMP http://www.mamp.info/en/index.html to get around this. 您可以使用XAMPP http://www.apachefriends.org/en/xampp-macosx.html或MAMP http://www.mamp.info/en/index.html来解决这个问题。

Also make sure you have a directive in your httpd-vhosts.conf 还要确保在httpd-vhosts.conf中有一个指令

Otherwise you get the same '403 forbidden in the browser', with 'the client denied by server configuration in the error log. 否则,您将在浏览器中获得相同的“403禁止”,并在错误日志中通过服务器配置拒绝客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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