2.12.8. Change cron working directory

The default working directory for running cron tasks is home.

Add the following lines to the beginning of the script being launched (use your own site name and path):

$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = 'GET';
chdir('/home/example/example.com/www/path/to/dir');
Use this method if you get an error like "cd: No such file or directory" when you start the task.
  1. Create a file with any name (for example, cron.sh) on the hosting server with the following content:
    #!/bin/bash
    here, specify the commands to be run
  2. Add a cron task and specify the path to the created file as the task itself.
Content