简体   繁体   中英

Cronjob causing 500 internal server error

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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