file_get_contents failed to open stream: Permission denied in xxx解决办法
来源:互联网 发布:满族饮食 知乎 编辑:程序博客网 时间:2024/06/05 23:56
新配的lamp环境,出现如下错误:
file_get_contents(http://x.x.x.x:9898/aa/bb/cc.php): failed to open stream: Permission denied in /var/www/html/a/b/c.php on line 3
很多网友说是文件夹权限错误,于是通过“chmod -R 777 /你的文件夹”更改所在文件夹的权限,但不起作用,还是报错。
几经痛苦测试排错,发现更换file_get_contents的url:“http://x.x.x.x:9898/aa/bb/cc.php”,发现不带端口的file_get_contents是正常的,所以肯定不是文件夹的权限问题,
再通过网友写的《file_get_contents不能获取带端口的网址》(http://www.111cn.net/phper/31/48374.htm),最终顺利解决。
解决办法如下:
例子
<?php
echo file_get_contents("test.txt");
?>
输出:
This is a test file with test text.
同样此函数还可以用于获取远程服务器上的内容
file_get_contents('http://www.111cn.net');
这样也是没有问题,但是如果我带了端口了就有问题了
例如:
file_get_contents('http://localhost:12345');
没有任何获取。
解决方法是 :关闭selinux
1 永久方法 – 需要重启服务器
修改/etc/selinux/config文件中设置SELINUX=disabled ,然后重启服务器。
2 临时方法 – 设置系统参数
使用命令setenforce 0
附:
setenforce 1 设置SELinux 成为enforcing模式
setenforce 0 设置SELinux 成为permissive模式
php的allow_url_fopen选项是关闭了
原因是我们php.ini中把php的allow_url_fopen选项是关闭了,我们只要把它打开即可。
如果你没有权限打开allow_url_fopen的话我们可使用curl函数的来替换,也是很方法的。
- file_get_contents failed to open stream: Permission denied in xxx解决办法
- failed to open stream: Permission denied in
- SAE failed to open stream: Permission denied in...
- PHP Warning: file_put_contents(".."):failed to open stream: Permission denied in...
- PHP failed to open stream: Permission denied
- linux下PHP项目写入日志失败,fopen(xxx.log): failed to open stream: Permission denied
- failed to open stream: Permission denied in Unknown on line 0
- 【解决问题】'failed to open stream:Permission denied in......'在php出现情况总结
- IIS下使用fopen报错failed to open stream: Permission denied in的解决方法
- easyhadoop:failed to open stream:Permission denied in /var/www/html/index.php
- PHP Warning: file_get_contents failed to open stream解决办法
- ecshop商城: failed to open stream: Permission denied
- <php+mysql>failed to open stream: Permission denied问题解决办法
- Lamp环境下:fopen failed to open stream:permission denied
- [乐意黎原创]PHP 写入文件时抛failed to open stream:Permission denied in 错误的解决方法
- failed to open stream解决办法
- 关于php使用fopen报错 failed to open stream: Permission denied
- laravel错误处理...app/storage/sessions...failed to open stream: Permission denied
- Head First SQL 第八章
- 《深入浅出nodejs》异步i/o笔记(1)
- svn不能打开 系统找不到
- Http请求中Content-Type讲解以及在Spring MVC注解中produce和consumes配置详解
- 欢迎使用CSDN-markdown编辑器
- file_get_contents failed to open stream: Permission denied in xxx解决办法
- oracle中merge into语句详解
- c++ 字符串流 sstream(常用于格式转换)
- OpenCV操作矩阵
- 使用ambari扩展hdfs节点
- Unity中的协同与线程
- MyBatis之resultMap的作用和xml配置折腾
- MySQL自增主键归零的方法
- 使用json所需的jar包