简体   繁体   中英

Laravel-medialibrary: How to set owner of files and conversions?

Problem is, that image files cannot be deleted via GUI, since the owner of the files is root (some images are created by a cronjob directly. There are also the conversions generated by medialibrary itself within a Laravel job.).

I did not find a way to tell medialibrary to set a specific owner. There is no method or configuration option for this.

Since medialibrary uses the Laravel filesystem, the configuration file filesystems.php could theoretically allow specifying an owner for all files in the medialibrary base directory. However, I only found a setting to specify permissions: https://laravel.com/docs/9.x/filesystem#local-files-and-visibility

All files created using the laravel framework and laravel-medialibrary will appear to be created by the user that runs the server of the webpage (apache2/nginx/php-fpm). Usually in linux system it will be somthing like www-data or httpd. Those files are accessible through your application and you can also delete them.

To be able to run laravel jobs though you need to setup a cron job. If that cron job is set in one of the /etc/cron.* folders or via crontab -e when you are root on your server that the specified command will be run with root priviledges and all created files will have root as owner. If you want to run the scheduled jobs as another user then you can use the following syntax:

* * * * * cd /path-to-your-project && su www-data -s php artisan schedule:run >> /dev/null 2>&1

where www-data is the name of the user that you want to appear as the owner of the files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM