Search code examples
phpapachesymfonynginximagick

Permission issue with Imagick and user www-data


I have an application build in Symfony2. The application runs in three Docker containers:

  • Nginx as reverse proxy and serving the static content
  • Apache as the webserver
  • Mysql for the database

All files are owned by root and the apache and nginx server runs under the user 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. First it makes an dir with permission 0755, with the following code:

@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. If I manually change the rights with:chmod -R 0755 dir then the images are shown correctly.

Any suggestion on how to store the images directly with the right premssions?


Solution

  • Can you use PHP chmod

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

    after creating file?