How to set up file permissions for Laravel?

前端 未结 15 2430
忘了有多久
忘了有多久 2020-11-22 00:08

I\'m using Apache Web Server that has the owner set to _www:_www. I never know what is the best practice with file permissions, for example when I create new La

15条回答
  •  深忆病人
    2020-11-22 00:28

    For Laravel developers, directory issues can be a little bit pain. In my application, I was creating directories on the fly and moving files to this directory in my local environment successfully. Then on server, I was getting errors while moving files to newly created directory.

    Here are the things that I have done and got a successful result at the end.

    1. sudo find /path/to/your/laravel/root/directory -type f -exec chmod 664 {} \;
      sudo find /path/to/your/laravel/root/directory -type d -exec chmod 775 {} \;
    2. chcon -Rt httpd_sys_content_rw_t /path/to/my/file/upload/directory/in/laravel/project/
    3. While creating the new directory on the fly, I used the command mkdir($save_path, 0755, true);

    After making those changes on production server, I successfully created new directories and move files to them.

    Finally, if you use File facade in Laravel you can do something like this: File::makeDirectory($save_path, 0755, true);

提交回复
热议问题