在PHP用使用fopen的写入功能实,常会遇到诸如:
PHP Warning: fopen(file): failed to open stream: Permission denied in (filepath) on line (num)的错误,特别是当在php.conf中建立了virtualhost,并指定了其它的目录的情况下会有可能出现(本人使用Fedora 20),附本人使用的virtualhost配置清单:
<VirtualHost 127.0.0.1:80>
ServerAdmin xqbumu@jx
DocumentRoot /opt/Workspace/PHP/jx
ServerName jx
ErrorLog logs/jx-error_log
CustomLog logs/jx-access_log common
<Directory "/opt/Workspace/PHP/jx/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
#Order allow,deny
#Allow from all
#Options None
Require all granted
</Directory>
</VirtualHost>
通过配置Selinux可以解决该问题。
本人所用shell命令如下:
semanage fcontext -a -t httpd_sys_rw_content_t '/opt/Workspace/PHP/jx/application/controllers/temp(/.*)?'
restorecon -v '/opt/Workspace/PHP/jx/application/controllers/temp/*'
这样就可以解决在/opt/Workspace/PHP/jx/application/controllers/temp/目录下的读写问题了。