简体   繁体   English

Imagick和用户www-data的权限问题

[英]Permission issue with Imagick and user www-data

I have an application build in Symfony2. 我在Symfony2中有一个应用程序构建。 The application runs in three Docker containers: 该应用程序在三个Docker容器中运行:

  • Nginx as reverse proxy and serving the static content Nginx作为反向代理并提供静态内容
  • Apache as the webserver Apache作为网络服务器
  • Mysql for the database MySQL的数据库

All files are owned by root and the apache and nginx server runs under the user www-data. 所有文件均由root拥有,并且apache和nginx服务器在用户www-data下运行。 The application runs fine. 该应用程序运行良好。

Only the php conjobs (runs under root on the host) makes new images and stores them on the server. 仅php conjobs(在主机上的root用户下运行)生成新映像并将其存储在服务器上。 First it makes an dir with permission 0755, with the following code: 首先,它使用以下代码创建一个权限为0755的目录:

@mkdir('path/..', 0755, true);

The dir is made with these rights correctly. 该目录正确地具有这些权限。 Then it stored an image in this dir with the following code: 然后,它使用以下代码在该目录中存储图像:

    $image = new \Imagick( 'path/filename.jpg' );

    $Width = $image->getImageWidth();
    $Height = $image->getImageHeight();

    if($Width > 1024 || $Height > 768) {
        $image->resizeImage($imgWith, $imgHeight, \Imagick::FILTER_LANCZOS, 0.9);
        $image->writeImage('path/new_filename.jpg');
    }

These images are only stored with 0600. Therefore the user www-data can not read / display the images in the application. 这些图像仅与0600一起存储。因此,用户www-data无法在应用程序中读取/显示图像。 If I manually change the rights with: chmod -R 0755 dir then the images are shown correctly. 如果使用以下命令手动更改权限: chmod -R 0755 dir则可以正确显示图像。

Any suggestion on how to store the images directly with the right premssions? 关于如何以正确的前提直接存储图像有什么建议吗?

Can you use PHP chmod 你可以使用PHP chmod吗

chmod('path/new_filename.jpg', 0755); chmod('path / new_filename.jpg',0755);

after creating file? 创建文件后?

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

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