douzuan2814 2013-03-08 07:56
浏览 273

Apache以用户nobody运行php脚本,cron以用户身份运行php脚本

My default cpanel set up runs apache as user "nobody". So when I run a php script via a browser that outputs a file, that file has ownership nobody:nobody. When I run the script from a cron job logged in as user "fred", the output files are owned by fred:fred I need both browser and cron to overwrite the same file. The issue I have is that if one "user" creates the file, the other one can't overwrite it. Please can you let me know where the fundamental problem is and a possible solution. Permissions on the files are 0775.

  • Do I need to set up groups - adding the user to the same group as nobody? If so how?
  • How do I get the cron job to run as user nobody?

Many thanks, Lloyd

  • 写回答

2条回答 默认 最新

  • dpafea04148 2013-03-08 08:14
    关注

    Try you code after changing permission of the file as 0777. But that creates a security issue as anyone can edit your file then.

    I have a logic you need to implement to:

    1. Create a shell script that copy the contents of temp file to your actual file.
    2. From PHP you need to update only temp file and Shell can read it as temp file will have read permission for everyone.
    3. Use ssh2_exec command to execute the shell script with your Linux UserName and Password.

    For ssh2_exec manual follow this link : http://php.net/manual/en/function.ssh2-exec.php

    Hope This will solve your problem.

    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度