Laravel file upload returns forbidden 403, file permission is 700 not 755

✔ Recommended Answer

The issue you are facing could be due to incorrect file permissions for the storage folder. Here are some steps to fix the problem:

  1. SSH into your cPanel server.

  2. Change the permission of the storage folder to 755:

    chmod -R 755 storage/

This command will change the permission of the storage folder and all its contents to 755, which should give the web server permission to read and write to the folder.

  1. Check the ownership of the storage folder. Ensure that the owner of the folder is the same as the user running the web server (typically www-data on Apache):

     ls -l

This command will list the files and folders in the current directory along with their ownership and permission details. Make sure that the owner of the storage folder is the same as the user running the web server.

  1. If the ownership is incorrect, you can change it using the following command:

      chown -R www-data:www-data storage/

This command will change the ownership of the storage folder and all its contents to the www-data user and group, which is typically used by Apache.

  1. Finally, make sure that the file upload path is correct. Check that the $model[0] and $data['id'] variables have the correct values and that the public directory is at the root of the web server.After making these changes, try uploading a file again and see if the issue is resolved.

After making these changes, try uploading a file again and see if the issue is resolved.

Method #2

A 403 Forbidden error typically indicates that the server understood the request but refuses to authorize it. This can happen if the file permissions are set incorrectly or if the file is not in the correct location.

If you are using Laravel to handle file uploads and are receiving a 403 error, it is possible that the file permissions are set to 700 instead of 755. File permissions of 700 only allow the owner of the file to read, write, and execute the file, while file permissions of 755 allow anyone to read and execute the file, but only the owner can write to it.

To fix this issue, you should change the file permissions to 755 using the following command:

bash
chmod 755 /path/to/file

If the file is located within your Laravel application, you may also need to adjust the permissions of the parent directory to allow the web server to access the file:

bash
chmod 755 /path/to/parent/directory

Once you have adjusted the file and directory permissions, you should be able to upload files without receiving a 403 error.

Comments

Most Popular

Remove Unicode Zero Width Space PHP

PhpStorm, return value is expected to be 'A', 'object' returned