RHEL + PHP:在/var/www/html 之外写入文件? [英] RHEL + PHP : writing files outside /var/www/html?

查看:39
本文介绍了RHEL + PHP:在/var/www/html 之外写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打开一个文件进行读/写.我一直在 Ubuntu 上开发,没有任何问题.现在是部署到 RHEL 服务器的时候了,我发现似乎对要写入的文件的位置有某种限制.

I'm trying to open a file for read/write. I've been developing on Ubuntu, and have had no problems whatsoever. Now it's time to deploy to the RHEL server, and I discover there seems to be some kind of restriction on the location of a file to be written.

在 RHEL 上,我无法打开文件,除非它位于/var/www/html 下.我不知道如何允许其他位置.出于磁盘空间管理的原因,我需要操作不同卷上的文件.

On RHEL, I can't open the file unless it's under /var/www/html. I can't figure out how to allow other locations. I need to manipulate files on a different volume, for disk space management reasons.

以下是无论如何在 Ubuntu 上都可以正常工作的代码,但如果文件位于 Web 根目录之外,则在 RHEL 上会中断:

The following is the bit of code that works fine on Ubuntu no matter what, but breaks on RHEL if the file is outside the web root:

$repometa = fopen( "/path/to/file/it/does/exist/and/has/good/perms", "r+b");

实际错误如下,这很奇怪,因为权限很好(由apache"用户拥有,文件上有 0644 个权限,目录上有 755 个权限).

The actual error is as follows, which is weird, because the permissions are just fine (owned by the "apache" user, with 0644 perms on file, 755 on dirs).

fopen(<thefile>): failed to open stream: Permission denied

有人能给我指点一下描述如何破解 RHEL 的 Apache/PHP 配置以允许写入文件系统上的备用位置的文档吗?

Can someone point me to the documents that describe how to un-break RHEL's Apache/PHP config to allow writing to alternate locations on the file system?

谢谢,~保罗

推荐答案

httpd_selinux(8) 手册页中所述,如果您希望能够读取或写入它们.有关详细信息,请参阅手册页,请记住,除非您专门将 PHP 设置为作为 CGI 运行,否则 PHP 脚本将作为守护程序运行.

As written in the httpd_selinux(8) man page, you must give files and directories specific file contexts if you want to be able to read from or write to them. See the man page for details, keeping in mind that PHP scripts run as the daemon unless you have specifically set up PHP to run as CGI.

这篇关于RHEL + PHP:在/var/www/html 之外写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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