Running php from crontab

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

Running php from crontab

Post by Nunners »

I'm being really thick... I've got various crons setup that run php scripts, and unfortunately my server went belly up recently so had to start from scratch. Got all the php files, and crontab list, but having problems running php from the crontab.

I know I had to put link in a "safe directory" to run php from, but can't remember how I did it... can anyone give me a hint, and this time I'll write down what I did!

Thanks
Nunners
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Running php from crontab

Post by AbraCadaver »

Depends. Is it /etc/crontab or a specific user's crontab?

As long as the php files are readable by the user who owns the crontab, then everything should be fine if you run them like: /usr/bin/php /path/to/file.php

If you run them like: /path/to/file.php because you have a #!/usr/bin/php at the top of the files, then the PHP file needs to be readable and executable by the user.

-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: Running php from crontab

Post by kaisellgren »

Make sure the file is indeed executable by the user. Once I wondered for a while why my crons failed. :) Also, it's likely a good idea to place the file below the doc root.
Post Reply