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:
chown -R $user:www-data /var/www/images.domain.com/
chmod g+s /var/www/images.domain.com
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.