在PHP用使用fopen的写入功能实,常会遇到诸如:
PHP Warning: fopen(file): failed to open stream: Permission denied in (filepath) on line (num)的错误,特别是当在php.conf中建立了virtualhost,并指定了其它的目录的情况下会有可能出现(本人使用Fedora 20),附本人使用的virtualhost配置清单:
1 <VirtualHost 127.0.0.1:80> 2 ServerAdmin xqbumu@jx 3 DocumentRoot /opt/Workspace/PHP/jx 4 ServerName jx 5 ErrorLog logs/jx-error_log 6 CustomLog logs/jx-access_log common 7 <Directory "/opt/Workspace/PHP/jx/"> 8 Options Indexes MultiViews FollowSymLinks 9 AllowOverride All 10 #Order allow,deny 11 #Allow from all 12 #Options None 13 Require all granted 14 </Directory> 15 </VirtualHost>
本人所用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/目录下的读写问题了。