Search code examples
phpchown

php chown() issue with apache user


I'm running a cron which is run under another user (not apache) and when I try to access apache's files it shows an error like:

fopen(): SAFE MODE Restriction in effect. 
The script whose uid is 10017 is not allowed to access ....

It's because safe_mode is turned on and it doesn't let me use apache's files (in this case uploaded files through the site). How can I overcome this? In php.net it says I have to be superuser to be able to change ownership which doesn't seem very secure to me ...


Solution

  • You run the PHP script through the 'php' interpreter (from a cron job) rather than through Apache's mod_php. This means you can enable and disable PHP's safe mode as you please.

    You should probably do something like php -d safe_mode=0 myscript.php.