简体   繁体   English

在FEDORA 20,APACHE拒绝许可

[英]PERMISSION DENIED on FEDORA 20, APACHE

Last week I installed Fedora 20 on my computer, create a web server (LAMP) and change the Document Root to my Dropbox folder. 上周我在我的电脑上安装了Fedora 20,创建了一个Web服务器(LAMP)并将Document Root更改为我的Dropbox文件夹。

From

/var/www/html 在/ var / www / html等

to

/home/ivnbrv/Dropbox /家庭/ ivnbrv / Dropbox的

At the start I found some problems with SELinux, googling I discovered that was solved in this way. 一开始我发现了SELinux的一些问题,谷歌搜索我发现这是以这种方式解决的。

$ chcon-R-u system_u-t httpd_sys_content_t /home/ivnbrv/Dropbox 

Then changing the owner of this directory which was set in 然后更改设置的此目录的所有者

/etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf中

User ivnbrv 
Group apache



$ chown-R ivnbrv.apache /home/ivnbrv/Dropbox 

Now when I try to upload a file using PHP 现在,当我尝试使用PHP上传文件时

move_uploaded_file () move_uploaded_file()

I see this error 我看到了这个错误

PHP Warning: move_uploaded_file (/ home/ivnbrv/Dropbox/Site/files/public/noticia/img/large/2010201.jpg): failed to open stream: Permission denied in / home / ivnbrv / Dropbox / Site / upload.php on line 113 PHP警告:move_uploaded_file(/ home / ivnbrv / Dropbox / Site / files / public / noticia / img / large / 2010201.jpg):无法打开流:/ home / ivnbrv / Dropbox / Site / upload.php中的权限被拒绝第113行

What can i do to make this work??? 我该怎么做才能使这项工作?

Since your situation is somewhat far from standard--ie your Document Root directory is within a homedir, among other things--I'd like to remind you that the following suggestions are provided solely for you to determine the main cause of your problem with permissions. 由于您的情况有点远离标准 - 即您的文档根目录位于homedir中,除其他外 - 我想提醒您以下建议仅供您确定问题的主要原因权限。 Keep in mind that the most important point of the SELinux system is to provide the minimum set of permissions needed ; 请记住,SELinux系统最重要的一点是提供所需的最小权限集 ; therefore, these steps are probably not all necessary, as they may further reduce the security of your system. 因此,这些步骤可能并非都是必需的,因为它们可能会进一步降低系统的安全性。

NOTE Additionally, perhaps most important, you need to make sure that your DAC policy allows the necessary rwx permissions to your server, since SELinux only goes into effect after the DAC permissions are allowed; 注意另外,也许最重要的是,您需要确保DAC策略允许对服务器进行必要的rwx权限,因为SELinux仅在允许DAC权限生效; ie if apache is not allowed rwx on the directory/file the DAC policy blocks it and SELinux doesn't even handle it. 即如果目录/文件中不允许使用apache,则DAC策略会阻止它,而SELinux甚至不会处理它。


  • Try changing the file context of the public directory and subdirs to public_content_rw_t . 尝试将public目录和子目录的文件上下文更改为public_content_rw_t

     # semanage fcontext -a -t public_content_rw_t "/home/ivnbrv/Dropbox/Site/files/public(/.*)?" 

followed by 其次是

    # restorecon -R -v /home/ivnbrv/Dropbox/Site/files/public/
  • Furthermore, you should check to make sure you have the proper sebooleans enabled with: 此外,您应该检查以确保您启用了适当的sebooleans

     # getsebool -a |grep -i http 

AFAIK, httpd_builtin_scripting , httpd_can_network_connect , and httpd_enable_homedirs should be set to on . httpd_builtin_scripting AFAIK, httpd_builtin_scriptinghttpd_can_network_connecthttpd_enable_homedirs设置为on

    # setsebool httpd_... on

Execute the command above for any booleans that need to be enabled. 对于需要启用的任何布尔值,执行上面的命令。 This change is temporary, however, unless you also add the -P option to setsebool to make it persistent. 但是,此更改是临时的,除非您还将-P选项添加到setsebool以使其持久化。

  • Check to make sure that your php-script(s) have the necessary file context with 检查以确保您的php脚本具有必要的文件上下文

     ls -alZ /path/to/dir/with/scripts 

If not, you can change them to httpd_sys_script_exec_t by executing 如果没有,您可以通过执行将它们更改为httpd_sys_script_exec_t

    # semanage fcontext -a -t httpd_sys_script_exec_t '/home/ivnbrv/Dropbox/Site/.*\/php5?'
    # semanage fcontext -a -t httpd_sys_script_rw_t '/home/ivnbrv/Dropbox/Site/files/public/noticia/img(/.*)?'
    # restorecon -R -v /home/ivnbrv/Dropbox/

As always, take a look at SELinux's wikipages for further details and information. 与往常一样,请查看SELinux的wikipages以获取更多详细信息。 There's also a wealth of useful information available on the fedora wiki pages with numerous scenarios and workflow methods; Fedora wiki页面上还提供了大量有用的信息,包括许多场景和工作流方法; as well as the official Fedora Docs - Security Guide . 以及官方的Fedora Docs - 安全指南

in your /etc/http/conf/httpd find lines like this: 在你的/ etc / http / conf / httpd中找到这样的行:

<Directory />
    AllowOverride none
    Require all denied
</Directory>

And add something like this: 并添加这样的东西:

<Directory /home>
        AllowOverride None
        Require all granted
</Directory>

Then restart you apache service 然后重启你的apache服务

Try set execution permission to: /home/ , /home/ivnbrv/ and /home/ivnbrv/Dropbox : 尝试将执行权限设置为: /home//home/ivnbrv//home/ivnbrv/Dropbox

chmod o+x /home/
chmod o+x /home/ivnbrv/
chmod o+x /home/ivnbrv/Dropbox

And restart your apache. 然后重启你的apache。

I recommend, add your user at group www-data (in my case) or apache: 我建议,将您的用户添加到www-data组(在我的情况下)或apache:

adduser your-user www-data

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

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