1

I am currently running an Ubuntu 14 linux server. That server acts as a CDN for real estate property images for my website. I used upstart to create a script which respawns a PHP image batcher script. The image batcher script and everything is running just fine. It connects to the database, selects a new property, creates a directory for the images, and downloads the images as expected.

The problem I am having is since the PHP file is in essence being called by root (since it runs as a service) all new image directories being created are owned by root instead of my ApachedUser:ApacheGroup.

The main issue with this is if for some reason an image download stops in the middle and doesn't grab all of its images, it won't let me go back in and download the remaining images since the folder is owned by root and not the apache user.

Things I have already done:

  1. chown -R $user:www-data /var/www/images.domain.com/
  2. chmod g+s /var/www/images.domain.com
  3. setfacl -Rdm d:www-data:rx /var/www/images.domain.com/

From everything I have ready this should cause any new files / folders created by a script to be owned by by my apache user and group.

From what I can tell however this is not the case. If I upload a file of any type to any folder under /var/www/images.domain.com it is owned by the FTP user and the group is set as the FTP user as well. My FTP User and Group defaults to the same as what apache should be.

Essentially I just need any file / folder under my /var/www/images.domain.com directory to be owned by $user:www-data by default, even for scripts that may be run by root.

1

Ok. So screwing around with things I think I managed to solve me issue.

For those using an Upstart script to fire and respawn PHP scripts you can add the following to your Upstart script to run as a specific user / group.

setuid $user setgid $group

Where $user and $group are the names of the specific user and group you want to run your script as.

My image directories are getting created now using appropriate ownership.

  • You should except your answer so that this question becomes closed. – Centimane Jun 17 '16 at 17:57
  • @Dave ITYM “accept”. You need to wait 48 hours before accepting your own answer, so Terry can't do it yet. – Gilles 'SO- stop being evil' Jun 18 '16 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.