Cronjob导致500内部服务器错误

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?

我正在服务器上运行CMS的演示。 在此演示中,潜在客户可以尝试CMS的后端。 这就是我创建一个删除整个CMS文件夹并将备份复制回其中的php脚本的原因。 这样,每次运行脚本时,都会重新启动演示站点。 p>

但事实上,我正在通过cron job找出如何做到这一点。 我使用的命令如下(我正在运行CentOS)。 p>

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

这将替换文件夹中的所有文件,但也会导致500内部服务器错误。 当我使用浏览器运行脚本时,问题不会出现。 p>

我还尝试将带有覆盖的.zip解压缩到demo文件夹中。 使用cPanel的文件管理器执行此操作,一切顺利。 使用unzip -o命令执行此操作会导致相同的错误。 p>

你们有谁知道怎么回事? p> div>

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.