mtlca401
mtlca401

Reputation: 11

getting php file to work with crontab

I have a php file that I can run from the browser and it works perfect. I tried to set up a cron job to run the php file, but am obviously missing something.

Since this php file was originally ran from the browser, it is uploaded to the /var/www folder. I made a copy of it in a new folder called /var/cron. I made this folder just to test. I will probably put it in another folder, but for now it is in this folder.

Here is what I did. After copying the php file to the /var/cron folder, I ran the crontab -e command to edit the crontab file. My cron job looks like this:

00,30,59 * * * * /var/cron/download.php

I have tried changing permissions by using chmod 755 download.php

that didn't do anything.

I have tried /usr/bin/wget -q /var/cron/download.php

this didn't do anything either.

What should I do?

Upvotes: 1

Views: 765

Answers (3)

Fakhrul I. Maruf
Fakhrul I. Maruf

Reputation: 11

Try with full URL like :

wget -O - -q "http://www.domain.com/cron.php"

Upvotes: 1

George Mandis
George Mandis

Reputation: 791

I'm a little surprised amccausl's approach didn't work for you.

Have you tried changing your crontab so it looks like this:

00,30,59 * * * * /usr/bin/php /var/cron/download.php

This assumes /usr/bin/php is where php lives on your server.

(You may also need to install a "cli" package for PHP, eg. Ubuntu/Debian's php5-cli.)

Upvotes: 1

Alex M
Alex M

Reputation: 3513

If you add

#!/usr/bin/php

as the first line of the php file, you can run it from the command line (as long as it has appropriate permissions. You can test run by going to the directory and typing

./download.php

Upvotes: 1

Related Questions