ERROR 403 in loading resources like CSS and JS in my index.php
Asked Answered
B

3

59

I'm in Linux, Elementary OS, and installed lampp in opt.

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.This is my workspace

This is the error enter image description here

enter image description here

Bosporus answered 10/9, 2013 at 16:51 Comment(3)
My first assumption is permission settings...Jarv
Permission as root? I tried running chromium as root, but no luck.Bosporus
Open a terminal, cd to the bootstrap_practice/bootstrap/css folder, type ls -la and add the result to your question so we can see who owns those files. If the localhost web server is Apache but the files are owned by root, Apache won't be able to open them.Caucasus
B
65

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.

Tip: I usually make the apache/nginx's user group owner of that kind of folders and give 775 permission to it.

Belle answered 10/9, 2013 at 16:58 Comment(4)
It should work if you do "sudo chmod 0777" inside that directory.Belle
For directories: chmod 755 and for files chmod 644. Run these two at the root of your site: find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \;Clutch
i have solved it by adding permission the folder - some time adding permission to individual file is not enoughAnarchic
@danielad that's right, the folder needs execute permission to be accessibleBelle
R
17

Find out the web server user

open up terminal and type 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:

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

If you give ownership of the web files to the web server:

chown www-data:www-data -R /opt/lamp/htdocs

And chmod 755 for good measure:

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

if it doesn't work, please give us the output of: ls -al /opt/lamp/htdocs

Readily answered 10/9, 2013 at 17:6 Comment(0)
S
1

A fast solution can be change permissions with:

sudo chmod -R 755

If you are managing a production server be careful and dont add a permission that you dont need.

Smog answered 18/9, 2021 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.