Apache上传文件/ tmp权限被拒绝

时间:2015-02-27 11:21:21

标签: php linux apache centos server

我有centos 7,我在上面安装了apache,并将文件根目录改为/ home / morteza / development。一切正常,但当我想上传文件时,它说:

  

move_uploaded_file(/home/morteza/development/news/data/news/54f04fb97482820150227023633online10-16px.png):无法打开流:第110行/home/morteza/development/news/core/assist.php中的权限被拒绝

我将apache用户和组添加到/ tmp和我的网站上传目录。这是getfacl / tmp:

file: tmp
owner: root
group: root
user::rwx
group::rwx
other::rwx 
default:user::rwx
default:group::rwx
default:group:apache:rwx
default:mask::rwx
default:other::rwx

同样适用于/ home / morteza / development / news / data,我想上传文件。 我在另一台服务器上使用相同的PHP代码,工作正常。这有什么问题?

附加:这是httpd:

的getsebool输出
httpd_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_connect_ftp --> off
httpd_can_connect_ldap --> off
httpd_can_connect_mythtv --> off
httpd_can_connect_zabbix --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> off
httpd_dbus_sssd --> off
httpd_dontaudit_search_dirs --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_graceful_shutdown --> on
httpd_manage_ipa --> off
httpd_mod_auth_ntlm_winbind --> off
httpd_mod_auth_pam --> off
httpd_read_user_content --> on
httpd_run_stickshift --> off
httpd_serve_cobbler_files --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_sys_script_anon_write --> off
httpd_tmp_exec --> off
httpd_tty_comm --> off
httpd_unified --> off
httpd_use_cifs --> off
httpd_use_fusefs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
httpd_use_openstack --> off
httpd_use_sasl --> off
httpd_verify_dns --> off

3 个答案:

答案 0 :(得分:0)

您需要为要将文件上载到的目录授予PHP读/写权限。通常在基于Linux的系统中,该用户称为www-data。

您可以使用此PHP脚本

进行检查
<?php
    echo exec("whoami");
?>

答案 1 :(得分:0)

是selinux。我禁用了selinux,它现在有效。但我现在不知道哪个配置是问题。现在我只是禁用selinux并在重新启动后工作。谢谢大家。

答案 2 :(得分:0)

我遇到了同样的问题(用户apache无法在Centos 7上写入/ tmp)。似乎PHP正在报告错误的目录,或者正在进行某种后台重定向。实际文件被写入:

/var/tmp/systemd-private-73473abd844a4c4382e2e87952f1eb3b-httpd.service-2SNEIV/

目录的所有者是root(目录的字母数字部分可能对每个人都不同):

drwxrwxrwt 2 root root 6 Feb 22 20:58 tmp

我将所有者更改为apache:

sudo chown -R apache /var/tmp/

导致的结果:

drwxrwxrwt 2 apache root 6 Feb 22 20:58 tmp

这是一种蛮横的方法,我仍在努力,但现在可以通过PHP上传文件。