解决CentOS 7.1上LNMP环境运行Laravel报 404 File not found . 错误。
来源:互联网 发布:苹果机下载不了软件 编辑:程序博客网 时间:2024/05/21 05:43
在CentOS 7和7.1上搭建出来的LNMP运行环境,PHP网站根目录设为/srv/www/default。
使用systemctl启动php-fpm时,浏览器会报个404错误
File not found.
但是用root权限手动使用php-fpm -D命令启动却一切正常。
仔细排查了几遍,原来是SELinux在作怪。先看看SELinux的介绍:
安全增强式 Security-Enhanced Linux(SELinux)是一个在内核中实践的强制访问控制(MAC)安全性机制。SELinux 首先在 CentOS 4 出现,并在后续的CentOS发行版中获得重大改善。这些改善代表用 SELinux 解决问题的方法亦随着时间而改变。SELinux 更能遵从最小权限的理念。在缺省的 enforcing 情况下,一切均被拒绝,接着有一系列例外的政策来允许系统的每个元素(服务、程序、用户)运作时所需的访问权。当一项服务、程序或用户尝试访问或修改一个它不须用的文件或资源时,它的请求会遭拒绝,而这个行动会被记录下来。由于 SELinux 是在内核中实践的,应用程序无须被特别编写或重写便可以采用 SELinux。当然,如果一个程序特别留意稍后所提及的 SELinux 错误码,它的运作可能会更畅顺。假若 SELinux 拦阻了一个行动,它会以一个标准的(至少是常规的)「拒绝访问」类错误来汇报给该应用程序。然而,很多应用程序不会测试系统函数所返回的错误码,因此它们也许不会输出消息解释问题所在,或者输出错误消息。
SELinux 拥有三个基本的操作模式,当中 Enforcing 是缺省的模式。此外,它还有一个 targeted 或 mls 的修饰语。这管制 SELinux 规则的应用有多广泛,当中 targeted 是较宽松的级别。
Enforcing: 这个缺省模式会在系统上启用并实施 SELinux 的安全性政策,拒绝访问及记录行动
Permissive: 在 Permissive 模式下,SELinux 会被启用但不会实施安全性政策,而只会发出警告及记录行动。Permissive 模式在排除 SELinux 的问题时很有用
Disabled: SELinux 已被停用
在CentOS 7.1上使用sestatus命令查看当前SELinux运行状态。
SELinux status: enabledSELinuxfs mount: /sys/fs/selinuxSELinux root directory: /etc/selinuxLoaded policy name: targetedCurrent mode: enforcingMode from config file: enforcingPolicy MLS status: enabledPolicy deny_unknown status: allowedMax kernel policy version: 28
可以看到当前是Enforcing模式在运行。
查看SELinux的配置文件
$ cat /etc/selinux/config# This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:# enforcing - SELinux security policy is enforced.# permissive - SELinux prints warnings instead of enforcing.# disabled - No SELinux policy is loaded.SELINUX=enforcing# SELINUXTYPE= can take one of these two values:# targeted - Targeted processes are protected,# minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection.SELINUXTYPE=targeted
可以看到开机也是Enforcing模式在运行。使用setenforce命令切换到Permissive模式。
$ sudo setenforce 0$ sestatus SELinux status: enabledSELinuxfs mount: /sys/fs/selinuxSELinux root directory: /etc/selinuxLoaded policy name: targetedCurrent mode: permissiveMode from config file: enforcingPolicy MLS status: enabledPolicy deny_unknown status: allowedMax kernel policy version: 28
再使用
sudo systemctl start php-fpm.service
启动php-fpm服务,这样LNMP服务就正常了
另一种解决方法是不改变SELinux的模式,改变网站根目录的权限。
sudo chcon -Rt httpd_sys_content_t /srv/www/su -c "chcon -R -h -t httpd_sys_script_rw_t /srv/www/"
- 解决CentOS 7.1上LNMP环境运行Laravel报 404 File not found . 错误。
- lnmp一键安装环境上laravel报500错误记录
- nginx报 File not found 错误
- nginx报 File not found 错误
- 解决React Native 运行在ios上报'boost/iterator/iterator_adaptor.hpp' file not found'错误
- nginx File not found 错误(转) 404
- Centos上运行g++c++:command not found
- 解决开机“xmnt2002 program file not found”错误
- 解决开机“xmnt2002 program file not found”错误
- Centos下报“is not in the sudoers file”错误
- 解决CentOS出现Class 'PDO' not found 错误
- centos解决bash: service: command not found 错误
- nginx File not found 错误
- nginx File not found 错误
- nginx File not found 错误
- nginx File not found 错误
- nginx File not found 错误
- nginx File not found 错误
- CListCtrl 设置选中状态
- 【linux】 linux gpio操作
- css内联对象和块对象 (
- 高性能计算中并行的概念理解
- 编译bazar包
- 解决CentOS 7.1上LNMP环境运行Laravel报 404 File not found . 错误。
- C++四种强制类型转换的总结
- C++学习笔记(十六):对vector进行更多的操作——泛型算法
- java中的clone()方法的研究---(2)浅克隆和深克隆
- 使用代码为textview设置drawableLeft
- VMware虚拟机中安装centos7.0图解过程
- DrawerLayout侧滑菜单按钮与返回按钮切换
- epoll网络编程实例
- Flume-ng与Mysql整合开发