简体   繁体   English

Laravel-medialibrary:如何设置文件和转换的所有者?

[英]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.).问题是,图像文件不能通过 GUI 删除,因为文件的所有者是 root(一些图像是由 cronjob 直接创建的。还有由 medialibrary 本身在 Laravel 作业中生成的转换。)。

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.由于 medialibrary 使用 Laravel 文件系统,配置文件filesystems.php理论上可以允许为 medialibrary 基目录中的所有文件指定所有者。 However, I only found a setting to specify permissions: https://laravel.com/docs/9.x/filesystem#local-files-and-visibility但是,我只找到了一个指定权限的设置: 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).使用 laravel 框架和 laravel-medialibrary 创建的所有文件似乎都是由运行网页服务器(apache2/nginx/php-fpm)的用户创建的。 Usually in linux system it will be somthing like www-data or httpd.通常在 linux 系统中,它会类似于 www-data 或 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.为了能够运行 laravel 作业,尽管您需要设置一个 cron 作业。 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.如果该 cron 作业设置在 /etc/cron.* 文件夹之一中或通过 crontab -e 当您在服务器上以 root 身份运行时,指定的命令将以 root 权限运行,并且所有创建的文件都将以 root 作为所有者。 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.其中 www-data 是您希望显示为文件所有者的用户的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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