Vagrant 与 apache 同步文件夹权限问题 [英] Vagrant synced folder permission issue with apache

查看:16
本文介绍了Vagrant 与 apache 同步文件夹权限问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个 Centos6.4 机器.

I'm running a Centos6.4 box.

在 Vagrant 文件中没有同步文件夹配置的情况下运行 vagrant up 很好.我可以通过 http://localhost:8080 在我的主机上访问它并显示 Apache 页面.我可以在 /var/www/html 文件夹中创建 index.html,它也显示得很好.

Running vagrant up without the synced folder config in Vagrant file is fine. I can access on my host machine via http://localhost:8080 and it displays the Apache page. I could create index.html in /var/www/html folder and it displays fine too.

但是在 Vagrant 文件中添加以下行后,访问页面显示 403 Forbidden You don't have permission to access to/on this server. 错误:

However after adding the line below in the Vagrant file, visiting the page displays 403 Forbidden You don't have permission to access / on this server. error instead:

config.vm.synced_folder "./source", "/var/www/html", :extra=>"dmode=777,fmode=777"

进入虚拟机,我在 /var/www 中看到如下权限集:

Going into the VM I see the permission set as below in /var/www:

drwxr-xr-x.  6 root    root    4.0K Jul 20 23:15 .
drwxr-xr-x. 18 root    root    4.0K Jul 20 23:15 ..
drwxr-xr-x.  2 root    root    4.0K May 14 06:12 cgi-bin
drwxr-xr-x.  3 root    root    4.0K Jul 20 23:15 error
drwxrwxrwx.  1 vagrant vagrant  102 Jul 21 23:14 html
drwxr-xr-x.  3 root    root    4.0K Jul 20 23:18 icons

所以我尝试设置 apache 所有权,

So I tried setting apache ownership to it,

   config.vm.synced_folder "./source", "/var/www/html", :owner=>"apache",:group=>"apache",:extra=>"dmode=777,fmode=777"

但这也行不通.

显然它具有完整的读/写权限,我不知道为什么 apache 会抱怨.

Apparently it has full read/write permissions and I have no clue why apache is complaining.

推荐答案

找出运行httpd的用户/组,确保用户对/var/www有执行权限,并其子文件夹.

Figure out the user/group which runs httpd, make sure the user has execute permission on /var/www and its subfolders.

另外,在你的 apache 站点配置文件中,确保你有正确的 /var/www 指令,如下所示

Also, in you apache site configuration files, make sure you have correct directives for /var/www, something like below

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

在guest中禁用SELinux,对开发环境没用

编辑/etc/selinux/config

将 SELINUX 改为禁用

Change SELINUX to disabled

SELINUX=disabled

重启 vagrant box => vagrant reload

Reboot the vagrant box => vagrant reload

看看#1 和#2 是否有帮助.

See if #1 with #2 helps.

这篇关于Vagrant 与 apache 同步文件夹权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆