You could hard-wire the Cake path into the environment. With multiple cake core versions on a single system, sometimes it is better not to do that, though. So I just follow the following guidelines:
- Only add the PHP path to the system environment path (not the cake one!)
- Always navigate to your app folder.
- Call your shells from there, either with
Console/cake(if you have an app Console folder with cake file) or
../lib/Cake/Console/cake(core cake file).
The documentation in the cookbook is pretty well written.
Here with a little bit more detailed explanation:
# m h dom mon dow command */5 * * * * cd /full/path/to/app && Console/cake myshell myparam
The tool Crontab is used here. This config file contains an example with a cronjob that is executed every 5 minutes. Basically, you just tell the script to navigate into your app folder and call your shell as you normally would as real user (always from inside your app folder).
If you don’t have an app cake file (I don’t for some older projects), you can also use the core cake file just as fine:
# m h dom mon dow command */5 * * * * cd /full/path/to/app && ../lib/Console/cake myshell myparam
You can edit the crontab for the www-data user, for example, using
crontab -e -u www-data
Using the user “www-data” (or a user that is affiliated with it) is advised to prevent running into issues with file access when creating or modifying files. It is also a security issue using a user with more or different rights than he should have or needs.
Also note that your “cake” file (either app or core) needs to be executable, so make sure you have set the appropriate rights for it.
CakePHP 2.x and windows
See the updated windows post for the correct path here. Also note the way more comfortable quick-links if you need to use 1.x and 2.x parallel.