Home  >  Article  >  Backend Development  >  linux - chmod命令之后安装php应用提示文件依然不可写

linux - chmod命令之后安装php应用提示文件依然不可写

WBOY
WBOYOriginal
2016-06-06 20:52:481265browse

我想要在自己的Linux系统下安装一些开源的php应用,譬如phpFreeChat,我把它放在/var/www/html/freechat底下,然后对freechat下的data文件夹中的public和private文件夹使用了chmod 777命令,然后使用ls -al data命令可以看到这样的结果:

drwxr-xr-x. 4 root root 4096 Jun 17 15:07 .
drwxr-xr-x. 13 root root 4096 Jun 17 15:22 ..
drwxrwxrwx. 2 root root 4096 Jun 17 15:07 private
drwxrwxrwx. 3 root root 4096 Jun 17 15:07 public

但是在浏览器里输入http://localhost/freechat 却会得到这样的错误:

phpFreeChat cannot be initialized, please correct these errors:

/var/www/html/freechat/src/../data/private is not writeable
/var/www/html/freechat/src/../data/private/cache can't be created
/var/www/html/freechat/src/../data/private/cache is not writeable
/var/www/html/freechat/src/../data/private/cache is not readable
cannot create /var/www/html/freechat/src/../data/public/themes/default
cannot create /var/www/html/freechat/src/../data/public/themes/default
/var/www/html/freechat/src/../data/private/chat can't be created
/var/www/html/freechat/src/../data/private/chat is not writeable
/var/www/html/freechat/src/../data/private/chat is not readable
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada can't be created
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada is not writeable
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada is not readable

还尝试过用递归的chmod命令,错误依旧。

利用代码

<?php echo exec('whoami'); ?>

发现用户名是apache,然后在/etc/httpd/conf/httpd.conf里发现User和Group都是apache。请问之所以显示文件不可写是因为这个用户的设置问题吗?如果是的话我该怎么修改?如果不是的话又是什么问题导致的呢?

回复内容:

我想要在自己的Linux系统下安装一些开源的php应用,譬如phpFreeChat,我把它放在/var/www/html/freechat底下,然后对freechat下的data文件夹中的public和private文件夹使用了chmod 777命令,然后使用ls -al data命令可以看到这样的结果:

drwxr-xr-x. 4 root root 4096 Jun 17 15:07 .
drwxr-xr-x. 13 root root 4096 Jun 17 15:22 ..
drwxrwxrwx. 2 root root 4096 Jun 17 15:07 private
drwxrwxrwx. 3 root root 4096 Jun 17 15:07 public

但是在浏览器里输入http://localhost/freechat 却会得到这样的错误:

phpFreeChat cannot be initialized, please correct these errors:

/var/www/html/freechat/src/../data/private is not writeable
/var/www/html/freechat/src/../data/private/cache can't be created
/var/www/html/freechat/src/../data/private/cache is not writeable
/var/www/html/freechat/src/../data/private/cache is not readable
cannot create /var/www/html/freechat/src/../data/public/themes/default
cannot create /var/www/html/freechat/src/../data/public/themes/default
/var/www/html/freechat/src/../data/private/chat can't be created
/var/www/html/freechat/src/../data/private/chat is not writeable
/var/www/html/freechat/src/../data/private/chat is not readable
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada can't be created
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada is not writeable
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada is not readable

还尝试过用递归的chmod命令,错误依旧。

利用代码

<?php echo exec('whoami'); ?>

发现用户名是apache,然后在/etc/httpd/conf/httpd.conf里发现User和Group都是apache。请问之所以显示文件不可写是因为这个用户的设置问题吗?如果是的话我该怎么修改?如果不是的话又是什么问题导致的呢?

问题解决了,竟然是SELinux从中作梗。使用setenforce 0以后便成功了。

应该是这个原因,你用chown -rf apache.apache /var/www/html/freechat/data/试试

chmod 777 -R /var/www/html/freechat/data

递归修改权限
或者向 @joyqi 说的把目录owner改成apache

chown -R apache:apache /var/www/html/freechat

Rpm系一定要记得setenforce 0,暂时关闭selinux后再测试

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn