duanduo0520 2014-11-02 13:40
浏览 20
已采纳

Cronjob导致500内部服务器错误

I am running a demo of a CMS on my server. In this demo, potential clients can try out the back-end of the CMS. This is why I created a php-script which deletes the whole CMS folder and copies a back-up back into it. This way, each time the script is run, the demo site is resored.

Thing is though, I am figuring out how to do this via cron job. The command I use is the following (I am running CentOS).

0 * * * * php /home/USER/public_html/replaceCMS.php

This replaces all files in the folder, but also causes a 500 internal server error. When I run the script using my browser, the problem does not appear.

I also tried unzipping a .zip with overwrite into the demo folder. Doing this with cPanel's file mananger, all went well. Doing it with unzip -o command causes the same error.

Does any of you know how come?

  • 写回答

1条回答 默认 最新

  • dstnlhhv791576 2014-11-02 14:41
    关注

    When the job is running as a root user, the files are likely going to be owned by root, which is not the same user as your web server. Thus, when you call the script via your browser, it is running with the user context of the webserver and not as root.

    You can verify this by running an ls -l on the command line and seeing what the owner is when you run it using the cronjob versus when you access the page using your browser.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部