1

I have a script (run as a cron) that creates a new folder called images on a server and moves images from the root folder to this new folder. Later another function will create thumbnails from these images and places these into another new folder named thumbs inside that same folder.

However, this function will only work if the parenting images folder has the owner set to 99 for some strange reason. The folder gets the user as its default owner.

How can I get the script to create a folder with the owner set to 99? Or what could be the reason that the PHP script has no power of chmod-ing files that have the user as the owner?

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Ruben
  • 189
  • 1
  • 3
  • 9

2 Answers2

2

The cron job is running as nobody (UID 99), so that user must have the appropriate permissions. You will need to have the cron job run as a different user if you don't want to change the permissions.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

Apparently it depends on how the php script was run in the cronjob to determine which owner will be set as the default on newly created files.

First I used:

/usr/local/bin/php /home/username/public_html/script.php > /home/username/public_html/file.xml 2>&1

But this created new folders with the owner set to the 'username'.

Instead using curl:

/usr/bin/curl -s http://domain.com/script.php > /home/username/public_html/file.xml 2>&1

Allowed the new files/folders to be created with the owner set to nobody (UID 99) which in its turn allowed the next script to create new folders/files inside this folder without a problem.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Ruben
  • 189
  • 1
  • 3
  • 9
  • When you run PHP from the command line it is 100% different than when you run PHP as a module via Apache. That’s why your `curl` method works. When you run it through `curl` the PHP script runs through the Apache module & then the permissions are set for the web server user which is exactly what you want. – Giacomo1968 Jul 13 '14 at 04:37