Salvador Dali
Salvador Dali

Reputation: 222879

Cronjob does not work

I know that this question was asked many times, but most of the answers are not really useful.

So I edited crontab with crontab -e. It was empty and I added just one line

*/1 * * * * php5 /var/www/cron.php which I think will be executing cron.php every 1 minute. I saved the file, but it clearly is not executed (inside my php file I have only

<?
$file = 'test.txt';
file_put_contents($file, "Work");

and it is not created. I looked and modified permissions on cron.php to 777. Php is installed as apache module.

What bothers me is that when I do php5 /var/www/cron.php from command line, I just see the content of the file and it not executed.

What am I doing wrong?

I also tried using full path with */1 * * * * /usr/bin/php5 /var/www/cron.php but also with no luck.

Upvotes: 0

Views: 162

Answers (2)

K.C. Tang
K.C. Tang

Reputation: 139

  • Try to use full path of php (e.g. /usr/local/bin/php)
  • Try to use <?php instead of <?

Upvotes: 0

Barmar
Barmar

Reputation: 782295

The first line of the script should be:

<?php

You may have short tags enabled in the Apache PHP configuration, but not the CLI PHP configuration.

Upvotes: 4

Related Questions