skip to Main Content

Trying to upload a file with opening new folder.
But laravel returns error like below.

    $destinationPath = public_path() . $folderName;
    if(!is_dir(public_path().'/uploads')) {
      mkdir(public_path().'/uploads', 0755, true);
    }
    $mkdir = mkdir(public_path().'/uploads/'.$unique, 0755, true);
    $success = file_put_contents(public_path().'/uploads/'.$unique."/".$filename, $file);

I used;

sudo chown -R nginx:nginx public/uploads
sudo chown -R root:root public/uploads
sudo chown -R $USER:$USER public/uploads

But nothing changed.
What’s wrong?

Is laravel’s nginx user different? How can I learn?

2

Answers


  1. you should check the Nginx user inside your Nginx config file.it can be found at /etc/nginx/nginx.conf and likely set to user www-data;

    Login or Signup to reply.
  2. Try running the command

    sudo chown -R www-data:www-data public/uploads
    

    This command should work. If now let me know.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search