0

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

Leif
  • 2,143
  • 2
  • 15
  • 26

1 Answers1

0

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.

parapente
  • 343
  • 3
  • 11
  • You're basically describing the problem. I know how to run cronjobs in another user context. I would use `crontab -e -u username`. The cronjobs are run by the Laravel Scheduler and have to be run as root, currently. – Leif Jun 03 '22 at 13:42
  • I wouldn't use `crontab -e -u username` for users with restrictive shells (like /usr/sbin/nologin or /bin/false) as that could lead to problems. If you must run the job as root then the cron job should take care of the file ownership as otherwise you cannot take ownership of root owned files. – parapente Jun 04 '22 at 07:52
  • Yes, trying to change the ownership appropriately is what I'm trying to achieve. However, I did not find a way to achieve this with laravel-medialibrary or the Laravel filesystem driver. – Leif Jun 07 '22 at 11:25