2014-02-19 21 views
2

我们的网站运行在Apache服务器上,使用httpd和php。在该服务器上安装一个来自Windows服务器的特定目录,比如说/mnt/some_directory/。我可以使用我自己的用户帐户使用WinSCP或SSH浏览此目录。允许Apache/PHP对安装的目录具有读/写访问权

我也可以执行SSH如下:

php -r "print_r(file_get_contents('/mnt/some_directory/file_name.txt'));" 

,看到文件的内容。

我们需要从该目录读取文件并进行解析,以便将其导入到网站使用的数据库中。但是,当在网站上的fopen或file_get_contents我们得到一个权限被拒绝的错误。

我对Web服务器的访问受限(以及有限的* nix和apache配置知识),但应该明显解决这个问题的管理员也缺乏这方面的知识,我需要解决这个问题,这就是为什么我在这里问。

管理员所做的是将安装目录的组和所有权设置为“apache”,这是httpd进程运行的用户。但是这并没有帮助。

据我所知默认情况下不允许访问webroot之外的文件。在httpd.conf中为/mnt/some_directory/设置一个DIRECTORY指令是否足够?或者还有什么要做的?

+0

可以链接目录一样的/ var/www/linkedtomntsomething?真的不知道它是否有效(现在无法测试) –

+0

它可能是Selinux权限问题。 –

+0

谢谢。根据'ps -ZC httpd',httpd进程由一个“unconfined_u”运行,所以我猜Selinux用户映射将用户“apache”映射为“unconfined_u”。为apache更改此映射会保存吗? –

回答

0

链接的安装目录您的www根目录和名称的链接“分享”

ln -s /mnt/some_directory /path/to/your/www/root/directory/share 

不是试图读取该文件

php -r "print_r(file_get_contents('/path/to/your/www/root/directory/share/file_name.txt'));" 

...或者你可以允许(如果你有足够的权限来编辑网络服务器的配置)

<Directory /mnt/somedirectory > 
    Allow from All 
<Directory> 
+1

我在''上试过一个指令,但它没有改变任何东西。 –

+0

试试这个:在你的里应该是里面应该是Options + FollowSymLinks指令。 – enterx

0

我看到了与cifs mo相同的问题unt linux/unix apache,用户可以访问已安装的卷,但不能访问apache。

也看到这一点:EnableSendfile关

但关闭时,Apache可能慢慢地工作, 在.htaccess,只为CIFS安装路径,它应该工作...。

http://httpd.apache.org/docs/current/en/mod/core.html

问候 L.Tomas

3

我们的团队有同样的问题,我的队友能够通过增加context安装选项来解决这个问题。

我们正在使用的安装窗口共享文件夹下面的格式到Linux Apache会能够访问:

mount -v -t cifs <//$hostname/$(windows shared dir)> <mount directory> -o username="<username>",password=<password>,domain=<domain name>,iocharset=utf8,file_mode=0777,dir_mode=0777,context="system_u:object_r:httpd_sys_content_t:s0" 

例如:

mount -v -t cifs //192.168.1.19/sample_dir /mnt/mount_dir -o username="admin",password=adminpwd,domain=MIINTER,iocharset=utf8,file_mode=0777,dir_mode=0777,context="system_u:object_r:httpd_sys_content_t:s0" 
相关问题