user723789
user723789

Reputation: 49

Trying to get php to run on cron

This is driving me a little insane, and I've gone through a hundered different things without touching on the solution; so I may miss out on some details on what I've done so far.

I'm trying to get a Cron job to run on my linux server ive got running in a datacentre. All I'm trying to get to run is a simple php script in the format:

* * * * * php -q /path/to/script/file.php

The php part runs fine if I type it in manually, but nothing happens when the cron runs; it also appears to run in the logs just fine, with no errors.

If i go back and edit with crontab -e, and put in the line

* * * * * echo "test" > /tmp/test.txt

That seems to work ok, it creates the text file.

Has anyone had any problems running a php script in this format?

(Btw I'm just testing with the run every minute, it doesnt work at any time.)

Any help is appreciated.

Upvotes: 1

Views: 203

Answers (5)

jishi
jishi

Reputation: 24604

try invoking php with it's full path, for example /usr/bin/php

the cron will not have the same environment variables as your user profile have, so it might not find the executable.

Upvotes: 2

Neil Aitken
Neil Aitken

Reputation: 7854

It's possible that you may need to provide the full path to your php binary

* * * * * /usr/bin/php -q /path/to/script/file.php

Upvotes: 0

Alex Howansky
Alex Howansky

Reputation: 53533

Perhaps your PHP binary is not in your PATH. Try using the full path:

* * * * * /path/to/php -q /path/to/script/file.php

Upvotes: 1

Femi
Femi

Reputation: 64700

Might just be some path craziness: I'd run which php and then copy the full path into cron. On one of my boxes it is /usr/bin/php and so you'd have:

* * * * * /usr/bin/php -q /path/to/script/file.php

Try that and see if it helps.

Upvotes: 1

Ostin
Ostin

Reputation: 1541

Try to put full path to php binary (/usr/bin/php or similar)

I also don't have '-q' flag in my distribution. Check it.

Upvotes: 1

Related Questions