Apache的权限,PHP文件创建,MKDIR失败 [英] Apache permissions, PHP file create, MKDir fail

查看:541
本文介绍了Apache的权限,PHP文件创建,MKDIR失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法创建文件。当我设置权限777在该文件夹我试图创建一个文件夹中,然后脚本工作正常。如果该文件夹设置为755,它失败。我不知道很多关于Linux,但我想算出这个东西出来。我花了几个小时尝试的东西。有谁知道如何使它这样Apache具有足够高的权限。

It seems i cannot create files. When i set permissions to 777 On the folder i am trying to create a folder in then the script works fine. If the folder is set to 755, it fails. I do not know much about linux, but i am suppose to figure this stuff out. I have spent a couple hours trying stuff. Does anyone know how to make it so that apache has high enough permissions.

结果
结果
我知道这是一个权限和Apache的问题,我只是不知道如何解决这个问题。我已经编辑httpd.conf文件,但我真的不知道我在做什么...任何帮助吗? (我保存的备份。)



I know it is a permissions and apache problem, i just do not know how to fix this. I have edited the httpd.conf file, but i really do not know what i am doing... Any help? (I saved backup.)

推荐答案

的建议停止使用777你让大家通过你的文件写的,其中pretty多意味着你失去了所有安全的许可制度是专为。如果您认为此,想想可能对配置不当的Web服务器的后果:它会成为非常容易黑客的网站,通过覆盖这些文件。所以,不要。

Please stop suggesting to use 777. You're making your file writeable by everyone, which pretty much means you lose all security that the permission system was designed for. If you suggest this, think about the consequences it may have on a poorly configured webserver: it would become incredibly easy to "hack" the website, by overwriting the files. So, don't.

迈克尔:有一个完全可行的原因,你的脚本不能创建目录,运行PHP的用户(可能是来自Apache不同)根本没有足够的权限来这样做。相反,更改权限的,我想你应该解决不了根本问题,这意味着你的文件有错误的所有者,或者Apache或PHP是错误的用户下运行。

Michael: there's a perfectly viable reason why your script can't create the directory, the user running PHP (that might be different from Apache) simply doesn't have sufficient permissions to do so. Instead of changing the permissions, I think you should solve the underlying problem, meaning your files have the wrong owner, or Apache or PHP is running under the wrong user.

现在,好像你已经安装了自己的服务器。您可以确定通过运行一个简单的脚本调用安装在大多数Linux版本的WHOAMI计划,用户正在运行PHP的:

Now, it seems like you have your own server installed. You can determine which user is running PHP by running a simple script that calls the 'whoami' program installed in most linuxes:

<?php
echo `whoami`;

如果一切是正确的,你应该看到的用户名PHP是下运行。根据您的操作系统,这可能是WWW的数据,没有人,HTTP,或任何变化。如果你的网站是唯一网站的运行,这很容易通过改变Apache下运行,用户更改。如果你有Debian的,就像我倾向于,您可以编辑文件/ etc /的Apache2 / envvars中(根),并更改APACHE_RUN_USER值。根据您的操作系统,这个变量可能会在不同的配置文件进行设置,因此,如果你不能找到它在/ etc / apache2的/ envvars中,请尝试使用搜索变量声明:

If all is right, you should see the username PHP is running under. Depending on your OS, this might be 'www-data', 'nobody', 'http', or any variation. If your website is the only website running, this is easy to change by changing the user Apache runs under. If you have Debian, like I tend to, you can edit the file /etc/apache2/envvars (as root), and change the value for APACHE_RUN_USER. Depending on your OS, this variable might be set in a different configuration file, so if you can't find it in /etc/apache2/envvars, try to search for the variable declaration by using:

$ grep -R "APACHE_RUN_USER=" .

从目录中的所有Apache的配置文件是

From the directory all apache-config files are in.

如果你不是在服务器上只有一个,你可能要考虑每一个网站创建用户帐户,并使用类似的Apache2-MPM-ITK改变,这取决于网站被称为RUN_USER。此外,还要确保PHP进程运行用户是文件的所有者和目录。您可以通过使用CHOWN实现这​​一目标:

If you're not the only one on the server, you might want to consider creating user accounts for every website, and using something like Apache2-MPM-ITK to change the RUN_USER depending on which website is called. Also, make sure that the user the PHP process is running under is the owner of the files, and the directories. You can accomplish that by using chown:

% chown theuser:theuser -R /var/www/website/

如果PHP与它自己的用户运行,并且是它需要写的文件和目录的所有者,权限700就足够了。我倾向于使用虽然750大多数文件我自己,因为我一般都在该组中多个用户,他们可以有阅读权限。所以,你可以更改权限:

If PHP is running with it's own user, and is the owner of the files and directories it needs to write in, the permission 700 would be enough. I tend to use 750 for most files myself though, as I generally have multiple users in that group, and they can have reading permissions. So, you can change the permissions:

% chmod 0750 -R /var/www/website/

这应该是它。如果您有问题,让我们知道,和请不要的不断占用,基本上告诉你什么建议:如果安全困扰你,删除安全

That should be it. If you having issues, let us know, and please don't ever take up any advice that essentially tells you: if security is bothering you, remove the security.

这篇关于Apache的权限,PHP文件创建,MKDIR失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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