简体   繁体   中英

Running PHP script via Cron

I'm codding a php script, using Instagram Private PHP Api.

It's work fine via SSH under "root" user, but when I try to run it via browser or cron, I getting error: Warning: chmod(): Operation not permitted in .....

I guess that something wrong with permissions, but I am not really good in server administration and can't understand what I can do =(

Please help, how I can fix this problem?

The user that PHP runs as must have permissions to chmod the given file or directory. If you're running this script via CRON, you get to set the user that PHP runs as right in the CRON job. If you're visiting the script in a browser, PHP is likely running as php or php-fpm or the web server user.

Simply ensure that the given file or folder is owned by the user that PHP runs as.

Note: It is not recommended that you run this script as root in CRON.

Because Apache (or the web server you're using) executes PHP using different Linux user (usually www-data ), which obviously have different permission than the user account you used in access via SSH.

To tackle the problem, you first have to know the folder / file you're going to chmod() belongs to who. If it belongs to root , then it's not suggested to chmod via any scripts that is accessible by public due to security concerns.

If it belongs to your user name, say foo , you can change the ownership of the folder / file you're going to chmod() to be accessible by www-data group using chown() in SSH console, then you chmod() command can be executed without problem.

If you are editing /etc/crontab , make sure the user parameter (the one after week) is root .

If you are editing crontab via crontab -e , add user parameter crontab -eu root .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM