简体   繁体   English

设置Crontab以在CentOS中执行PHP脚本

[英]Setting Up Crontab to Execute a PHP Script in CentOS

I have searched hell and high water for a solution to a problem I'm having in CentOS. 我已经在地狱和高空搜寻了CentOS中遇到的问题的解决方案。 I'm trying to set up a cron job that executes a PHP script. 我正在尝试设置一个执行PHP脚本的cron作业。 I was able to get this working using wget , but now that we are going into production, I need to find a way to do this whilst being more secure, as the cron job itself works with sensitive data. 我能够使用wget正常工作,但是现在我们要投入生产,由于cron作业本身可以处理敏感数据,因此我需要找到一种在提高安全性的同时进行此操作的方法。

The error that I'm getting is: -bash: php: command not found . 我得到的错误是: -bash: php: command not found

Now I've looked around and I've seen people having the same problem, but nothing has been able to help me get this working. 现在,我环顾四周,看到人们也遇到了同样的问题,但是没有什么能帮助我解决这个问题。

For reference, here is what the working crontab looked like using the wget command. 作为参考,这是使用wget命令的工作crontab的wget

* * * * * wget http://www.domain.com/cron_script.php

This is working fine, but I need to translate this into executing via PHP, rather than making an HTTP request to get the job done. 这工作正常,但是我需要将其转换为通过PHP执行,而不是发出HTTP请求来完成工作。

Let me know if I left anything out. 让我知道是否遗漏了什么。

Cron doesn't have it's PATH set. Cron没有设置PATH。 The easiest thing is to change the php command to the full path of the php binary. 最简单的方法是将php命令更改为php二进制文件的完整路径。

/usr/bin/php /path/to/yourscript.php

I'm fairly certain that's the path in CentOS but you can know for sure by doing which php on the command line and it will tell you. 我相当确定这是CentOS中的路径,但是您可以通过在命令行上执行which php来肯定地知道which php ,它会告诉您。

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

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