duanjing3656 2019-03-01 02:18
浏览 99


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?

  • 写回答

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.




  • ¥20 python 3des pyDes库
  • ¥15 关于#mysql#安装失败的问题。MySQL
  • ¥15 想问一下for循环计算表达式的方法,第一次接触
  • ¥15 如何在VA框架上面加功能,去读取框架内任何app数据功能
  • ¥15 关于#c语言#的问题:用c或c++写一个计算下列问题有关软件工程的代码并加上分析
  • ¥15 Zeppelin0.10.0版本升级lib包下的shiro-web
  • ¥15 链表入队的指针内存问题
  • ¥20 vba如何写本地html文件执行js
  • ¥15 VS2022的C#如何创建
  • ¥20 关于#用户注册#的问题,如何解决?