Tuesday, January 19, 2016

[Vtiger] Scheduler Cron Job Not Working: Access Denied

Here is the working method to run cron job with vtiger 6 under any linux, unix type host, even the shared hosts.

1. edit the /vtiger_root/vtigercron.php file.
in the line 42 there is a condition php_sapi === "cli" . change the "cli" value to the right php_sapi value of your server. it can be different server by server.
to obtain the right php_sapi value insert a line before the line 42 to this file.
the inserted line is: echo(php_sapi."\n");
it will echo your php_sapi value.

save the change.

2. edit the /vtiger_root/cron/vtigercron.sh file.
comment out all shell commands from this file and put the following command instead of:
wget http://yourdomain_vtigerurl/vtigercron.php -o /vtiger_root/log/cronlog.txt

save the change.

3. create an empty text file in the /vtiger_root/log/ folder with the name cronlog.txt

4. set the correct access permissions for the above mentioned files:
cronlog.txt chmod 755
vtigercron.sh chmod 755
vtigercron.php chmod 755

755 is enough. the most of system will show 'error 500' if a file has 777 permissions. it is the security issue.

5. create a cron job using the proper interface (for example in the c-panel there is an interface for the setup cron jobs):

*/15 * * * * sh /vtiger_root/cron/vtigercron.sh >/dev/null 2>&1

this command will run in every 15 minutes and call the vtigercron.sh that will execute the vtigercron.php file. the result of executing with all messages will save into the /vtiger_root/log/cronlog.txt

after the first run of the cron you should check the content of the cronlog.txt. the first line of the file will show you the exact value of the php_sapi in your server.

6. go back to the point 1, the /vtiger_root/vtigercron.php file
and change the "cli" value to the right php_sapi value of your server.

comment out or delete the line echo(php_sapi."\n");
and save your change.

7. check the content of the /vtiger_root/log/cronlog.txt after the new run of the cron job.
the file will show the exact state of the crons. you will see something like these lines:
[cron],"1396701901.848",http://yourdomain_vtigerurl/,instance,"2014-04-05 12:45:01","",[starts]
[cron],"1396701901.848",http://yourdomain_vtigerurl/,workflow,"2014-04-05 12:45:01","",[starts]

[cron],"1396701901.848",http://yourdomain_vtigerurl/,workflow,"2014-04-05 12:45:01","2014-04-05 12:45:01",[ends]
[info] recurringinvoice - not ready to run as the time to run again is not completed
[cron],"1396701901.848",http://yourdomain_vtigerurl/,sendreminder,"2014-04-05 12:45:01","",[starts]

[cron],"1396701901.848",http://yourdomain_vtigerurl/,sendreminder,"2014-04-05 12:45:01","2014-04-05 12:45:01",[ends]
[cron],"1396701901.848",http://yourdomain_vtigerurl/,mailscanner,"2014-04-05 12:45:01","",[starts]
no mailbox configured for scanning!
[cron],"1396701901.848",http://yourdomain_vtigerurl/,mailscanner,"2014-04-05 12:45:01","2014-04-05 12:45:01",[ends]
[cron],"1396701901.848",http://yourdomain_vtigerurl/,scheduled import,"2014-04-05 12:45:01","",[starts]

[cron],"1396701901.848",http://yourdomain_vtigerurl/,scheduled import,"2014-04-05 12:45:01","2014-04-05 12:45:02",[ends]
[cron],"1396701901.848",http://yourdomain_vtigerurl/,instance,"2014-04-05 12:45:01","2014-04-05 12:45:02",[ends]

8. check the vtiger 6 admin settings section "scheduler" and check the state of crons.
(from vtiger.com)

No comments: