2.11.8. Changing cron's working directory
The default working directory for running cron jobs is home
.
To run a PHP script
Add to the beginning of the running script:
$_SERVER['HTTP_HOST'] = 'name_site '; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['REQUEST_METHOD'] = 'GET'; chdir('/home/name_hosting_account/name_site/subdomain/path/to/directory');
To execute Linux commands
Use this method if you get an error like "cd: No such file or directory".
- Create a hosting file with any name (for example,
cron.sh
) and the following content:#!/bin/bash specify the commands to be run
- Add cron task and specify the path to the created file as the task itself.