duanjing3656
2019-03-01 02:18
浏览 99
已采纳

通过Cron运行PHP脚本

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?

图片转代码服务由CSDN问答提供 功能建议

我正在编写一个PHP脚本,使用Instagram私有PHP Api。

在“root”用户下通过SSH工作正常,但当我尝试通过浏览器或cron运行时,我收到错误:警告:chmod():操作不允许.....

我认为权限有问题,但我在服务器管理方面并不是很好,也无法理解我能做什么=(

请帮忙,我该如何解决这个问题?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • doubairan4213 2019-03-01 02:52
    已采纳

    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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • duanhao5038 2019-03-01 02:31

    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.

    评论
    解决 无用
    打赏 举报
  • duanming0494 2019-03-01 02:58

    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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题