简体   繁体   English

Cronjob导致500内部服务器错误

[英]Cronjob causing 500 internal server error

I am running a demo of a CMS on my server. 我正在服务器上运行CMS演示。 In this demo, potential clients can try out the back-end of the CMS. 在此演示中,潜在客户可以试用CMS的后端。 This is why I created a php-script which deletes the whole CMS folder and copies a back-up back into it. 这就是为什么我创建了一个PHP脚本,该脚本删除了整个CMS文件夹并将备份复制回该文件夹。 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. 事实是,我正在弄清楚如何通过cron作业做到这一点。 The command I use is the following (I am running CentOS). 我使用的命令如下(我正在运行CentOS)。

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

This replaces all files in the folder, but also causes a 500 internal server error. 这将替换文件夹中的所有文件,但也会导致500个内部服务器错误。 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. 我还尝试将覆盖的.zip解压缩到demo文件夹中。 Doing this with cPanel's file mananger, all went well. 用cPanel的文件管理员执行此操作,一切进展顺利。 Doing it with unzip -o command causes the same error. 使用unzip -o命令执行此操作会导致相同的错误。

Does any of you know how come? 你们中有人知道怎么来吗?

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. 当作业以root用户身份运行时,文件很可能将由root拥有,该root与您的Web服务器不是同一用户。 Thus, when you call the script via your browser, it is running with the user context of the webserver and not as root. 因此,当您通过浏览器调用脚本时,该脚本是在Web服务器的用户上下文中运行的,而不是以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. 您可以通过在命令行上运行ls -l并查看使用cronjob运行它与使用浏览器访问该页面时所有者的身份来验证这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM