0

I have an php file to create a new text file . That has to run in every minute . I stored that file on /var/www/html/cron.php . Also i had done in command prompt

crontab -e

edit the file like

* * * * * /var/www/html/cron.php

But still cron not working on localhost

shahaf
  • 4,750
  • 2
  • 29
  • 32
  • 2
    Possible duplicate of [Execute PHP script in cron job](https://stackoverflow.com/questions/22358382/execute-php-script-in-cron-job) – l'L'l Jun 08 '18 at 08:09
  • Try redirecting the output of cron to a file to see the logs. for ex [ * * * * * /var/www/html/cron.php" >/var/log/cron.log 2>&1 ] – Count Jun 08 '18 at 08:23
  • `sudo service cron reload` is your best friend here. – Gergely Lukacsy Jun 08 '18 at 09:15
  • Also, if your script has no php-shebang (the first line of the code is #!/usr/bin/php) and it isn't executable, then you need to change that line to `* * * * * /usr/bin/php /var/www/html/cron.php` – Gergely Lukacsy Jun 08 '18 at 09:21

3 Answers3

3

you need to specify in the cron the command to execute, i.e

[cron time] [command to execute]

/var/www/html/cron.php is not a command just a file, you need to use something like

* * * * * php /var/www/html/cron.php 

*better to use full path of php bin instead of php

shahaf
  • 4,750
  • 2
  • 29
  • 32
1

The command you put in crontab should be something like:

*/10 * * * *   /usr/bin/php  /var/www/html/cron.php

Where /usr/bin/php is an example path to your php binary.

You can find out your php binary with:

whereis php
Shuwn Yuan Tee
  • 5,578
  • 6
  • 28
  • 42
0

This should work:

*/1 * * * * cd /var/www/html;./cron.php
Walid Da.
  • 948
  • 1
  • 7
  • 15