Linux 在我的 index.php 中加载 CSS 和 JS 等资源时出现 ERROR 403
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18724718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR 403 in loading resources like CSS and JS in my index.php
提问by Mark Vizcarra
I'm in Linux, Elementary OS, and installed lampp in opt.
我在 Linux 和 Elementary OS 中,并在 opt 中安装了 lampp。
My CSS and JS won't load. When I inspect my page through browser. The console says
Failed to load resource: the server responded with a status of 403 (Forbidden)
I'm really sure that my directories are correct.
我的 CSS 和 JS 无法加载。当我通过浏览器检查我的页面时。控制台显示无法加载资源:服务器响应状态为 403(禁止)我真的很确定我的目录是正确的。
This is the error
这是错误
采纳答案by Edson Horacio Junior
You need to change permissions on the folder bootstrap/css. Your super user may be able to access it but it doesn't mean apache or nginx have access to it, that's why you still need to change the permissions.
您需要更改文件夹 bootstrap/css 的权限。您的超级用户可能可以访问它,但这并不意味着 apache 或 nginx 可以访问它,这就是您仍然需要更改权限的原因。
Tip: I usually make the apache/nginx's user group owner of that kind of folders and give 775 permission to it.
提示:我通常将此类文件夹的 apache/nginx 用户组所有者设置为 775 权限。
回答by Joeme
Find out the web server user
找出网络服务器用户
open up terminal and type
lsof -i tcp:80
打开终端并输入
lsof -i tcp:80
This will show you the user of the web server process Here is an example from a raspberry pi running debian:
这将向您显示 Web 服务器进程的用户 以下是运行 debian 的 raspberry pi 的示例:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
apache2 7478 www-data 3u IPv4 450666 0t0 TCP *:http (LISTEN)
apache2 7664 www-data 3u IPv4 450666 0t0 TCP *:http (LISTEN)
apache2 7794 www-data 3u IPv4 450666 0t0 TCP *:http (LISTEN)
The user is www-data
用户是 www-data
If you give ownership of the web files to the web server:
如果您将 Web 文件的所有权授予 Web 服务器:
chown www-data:www-data -R /opt/lamp/htdocs
And chmod 755 for good measure:
和 chmod 755 很好的措施:
chmod 755 -R /opt/lamp/htdocs
Let me know how you go, maybe you need to use 'sudo' before the command, i.e.
sudo chown www-data:www-data -R /opt/lamp/htdocs
让我知道你怎么走,也许你需要在命令前使用“sudo”,即
sudo chown www-data:www-data -R /opt/lamp/htdocs
if it doesn't work, please give us the output of:
ls -al /opt/lamp/htdocs
如果它不起作用,请给我们输出:
ls -al /opt/lamp/htdocs