Cant access images and files in laravel public directory - 403 Forbidden - digitalocean

Viewed 344

I deployed my laravel project on digital ocean LEMP .

What is the problem I have?

The problem I have is that images, css and js files are not loaded from public folder. It seems like I have a problem with permissions.

I have these folders in Public folder:

img, photos, css, js,

After inspect i find this error :

Status Code: 403 Forbidden

This is the root folder permission:

drwxrwxr-x 13 www-data www-data 4096 Nov 9 16:36 laravelproject

Project folders permissions:

-rw-rw-r--  1 www-data www-data   3851 Nov  9 16:29 README.md
drwxrwxr-x 10 www-data www-data   4096 Nov  9 16:29 app
-rwxrwxr-x  1 www-data www-data   1686 Nov  9 16:29 artisan
drwxrwxr-x  3 www-data www-data   4096 Nov  9 16:29 bootstrap
-rw-rw-r--  1 www-data www-data   2116 Nov  9 16:29 composer.json
-rw-rw-r--  1 www-data www-data 344507 Nov  9 16:29 composer.lock
drwxrwxr-x  2 www-data www-data   4096 Nov  9 16:29 config
drwxrwxr-x  5 www-data www-data   4096 Nov  9 16:29 database
-rw-rw-r--  1 www-data www-data 743285 Nov  9 16:29 package-lock.json
-rw-rw-r--  1 www-data www-data    768 Nov  9 16:29 package.json
-rw-rw-r--  1 www-data www-data   1202 Nov  9 16:29 phpunit.xml
drwxr-xr-x 10 www-data www-data   4096 Nov  9 16:29 public
drwxrwxr-x  9 www-data www-data   4096 Nov  9 16:29 resources
drwxrwxr-x  2 www-data www-data   4096 Nov  9 16:29 routes
-rw-rw-r--  1 www-data www-data    563 Nov  9 16:29 server.php
drwxrwxr-x  5 www-data www-data   4096 Nov  9 16:29 storage
drwxrwxr-x  4 www-data www-data   4096 Nov  9 16:29 tests
drwxrwxr-x 60 www-data www-data   4096 Nov  9 16:31 vendor
-rw-rw-r--  1 www-data www-data    679 Nov  9 16:29 webpack.mix.js

Public folder Content Permissions:

drwxr-xr-x 5 www-data www-data 4096 Nov  9 16:29 assets
drwxr-xr-x 4 www-data www-data 4096 Nov  9 16:29 backend
drwxr-xr-x 4 www-data www-data 4096 Nov  9 16:29 css
-rwxr-xr-x 1 www-data www-data    0 Nov  9 16:29 favicon.ico
drwxr-xr-x 3 www-data www-data 4096 Nov  9 16:29 fonts
drwsr-sr-x 5 www-data www-data 4096 Nov  9 16:29 img
-rwxr-xr-x 1 www-data www-data 1735 Nov  9 16:29 index.php
drwxr-xr-x 2 www-data www-data 4096 Nov  9 16:29 js
drwxr-xr-x 2 www-data www-data 4096 Nov  9 16:29 langs
-rwxr-xr-x 1 www-data www-data  173 Nov  9 16:29 mix-manifest.json
-rwxr-xr-x 1 www-data www-data   24 Nov  9 16:29 robots.txt
drwxr-xr-x 3 www-data www-data 4096 Nov  9 16:29 vendor
-rwxr-xr-x 1 www-data www-data 1183 Nov  9 16:29 web.config

Nginx log

2021/11/09 19:00:57 [error] 48608#48608: *92 access forbidden by rule

1 Answers

In case someone faced an issue like this.

If you're running Linux, most likely it's a read/write permission problem, to solve these problems, do the following:

Before doing the steps below, be sure to be outside of your Laravel folder

Assuming that your user should be the owner, type the following command:

sudo chown -R user:www-data /path/of/your/laravel/project Then give the user and webserver permissions as follows:

sudo find /var/www/project -type f -exec chmod 664 {} ; then run:

sudo find /var/www/project -type d -exec chmod 775 {} ; After you run those commands, go to your Laravel folder and give the webserver rights to read/write to your bootstrap/cache and storage folder:

sudo chgrp -R www-data storage bootstrap/cache sudo chmod -R ug+rwx storage bootstrap/cache It should solve not only your problem but also solves your project security.

Related