#1 By: Jason, May 22nd, 2012 18:46
I'm surprised that the Bitnami Moodle image (ubuntu) when set up and running doesn't appear to have the moodle/htdocs/admin/cli/cron.php running automatically.
I had a warning message from Moodle stating that cron had not be excuted for a long time, so I ran it manually from the command line.
Am I missing something here? What should I do? Should I create my own with crontab. Is there any documentation on this?
#2 By: Beltran Rueda Borrego, May 24th, 2012 04:39
#3 By: deverezieaux, July 24th, 2012 10:34
I'm setting up Moodle 2.3 on Amazon EC2 and having the same difficulty setting up cron. I'm doing it from the Bitnami console through Amazon EC2.
After running "/5 * * * su daemon -c '/opt/bitnami/php/bin/php /opt/bitnami/apps/moodle/htdocs/admin/cli/cron.php >/dev/null" (I'm trying to run cron every 5 minutes).
I get the error: "E486 Pattern Not found: 5* su daemon -c"
Can I manually add the task to cron.php? If so, how can I do this? Or is there something else I can do?
#4 By: Beltran Rueda Borrego, July 24th, 2012 14:16
sorry, this is not a command. When your run the "crontab -e" command you should be able to edit a file. You only need to add this line on that file.
#5 By: deverezieaux, July 25th, 2012 00:19
I was able to determine I had skipped a step of saving the crontab. Pressing "i" to insert the text, "Esc" and entering ":wp!" to save seemed to work.
I saved: "/5 * * * su daemon -c '/opt/bitnami/php/bin/php /opt/bitnami/apps/moodle/htdocs/admin/cli/cron.php >/dev/null" to run cron every 5 minutes.
However it doesn't appear to be running. The Moodle notifications tab indicates that cron still hasn't been run for 24 hours. Any advice you could offer would be incredibly helpful. This is the last step for our instance.
#6 By: Beltran Rueda Borrego, July 25th, 2012 13:23
try to redirect the output to a file instead of /dev/null, for example >/tmp/log.txt and check if this file was created. Note that you have to run the "crontab -e" command with sudo to create this task in the root crontab:
$ sudo crontab -e
#7 By: deverezieaux, July 26th, 2012 12:36
I placed the task in the root crontab using "sudo crontab -e" and let it run for a while, but unfortunately this produced no log.txt in /tmp. I also tried placing it under bitnami using just "crontab -e" and let it run, but this also produced no log.txt.
I'm currently running cron as a task from a separate Windows machine, but this is obviously not an ideal, long-term solution.
Is it possible that the structure for " '/opt/bitnami/php/bin/php" is incorrect? I ran into this issue when looking for php.ini earlier in the installation. the file "/opt/bitnami/php/" doesn't exist.
#8 By: Beltran Rueda Borrego, July 27th, 2012 06:13
It is strange, are you using the BitNami Moodle Amazon image right? In this case /opt/bitnami/php folder should exist.
#9 By: deverezieaux, July 30th, 2012 10:25
I am using the Bitnami Moodle AMI. In another posting of mine on these forums, Kaysa pointed out the following in regard to directory structure:
"Notice that our RedHat images use the system php. In /opt/bitnami/properties.ini you can find information about the components used. For php you will see an entry like this:
This means that php.ini is located in /etc/php.ini."
If I'm not mistaken this would also affect the location of "/opt/bitnami/php/bin/php"
Pardon the delayed response from me, I missed your response.
#10 By: kaysa, July 30th, 2012 13:22
Hi, you should try using /usr/bin/php instead. Also if it still fails try to execute as root user:
su daemon -c '/opt/bitnami/php/bin/php /opt/bitnami/apps/moodle/htdocs/admin/cli/cron.php
Also check in the properties.ini if the apache user is daemon or anything else. In some systems it runs as nobody.
#11 By: deverezieaux, July 30th, 2012 15:40
The user is actually listed as a "apache". I also noticed that there is no /usr/bin/php directory, only /usr/bin/ not sure why that is. I haven't changed the directory structure at all. I'll try running the commands you suggest. Thank you!
#12 By: deverezieaux, July 30th, 2012 16:57
Unfortunately neither of these suggested changes worked. I tried running them both as "daemon" and "apache". I conducted a search for the PHP file and it is in usr/bin/.
#13 By: deverezieaux, July 30th, 2012 20:39
Here's what I've tried:
"/5 * * * su daemon -c '/usr/bin/php /opt/bitnami/apps/moodle/htdocs/admin/cli/cron.php >/tmp/log.txt" using both sudo crontab -e and crontab -e.
Also tried "apache" and "bitnami" instead of daemon. PHP is owned by root, cron.php is owned by bitnami, but properties.ini says apache is run by user "apache".
Running "sudo php /opt/bitnami/apps/moodle/htdocs/admin/cli/cron.php" from the command line worked. I received this error: "!!! Detected incorrect $CFG->wwwroot in config.php, it must not contain trailing slash." I changed wwwroot temporarily to run this.
#14 By: deverezieaux, July 30th, 2012 22:31
The cron job is now running successfully as:
"/5 * * * sudo php /opt/bitnami/apps/moodle/htdocs/admin/cli/cron.php >/dev/null"
I'm sure this is not the best way to write this job, but it works.
In order to make this work I had to change /moodle/htdocs/config.php. I had to change wwwroot to the URL of my EC2 instance. It had to be the EC2 URL, not my domain name, or the site became unreachable.
I tried running it beginning with "su daemon", "su apache" and "su bitnami". When I did this the log.txt file indicated "The user is not available."
Is there a better way to write this job?
#15 By: gaz0303, August 7th, 2012 19:08
Similar problem. Running from web using domain/admin/cron.php? works but I cant get working with crontab. Followed Beltrans instructions to set up and changed output to /tmp/log.txt but no output appears. Also tried running "/opt/bitnami/php/bin/php /opt/bitnami/apps/moodle/htdocs/admin/cli/cron.php" from cmd line and get following error
"PHP Notice: Undefined index: HTTP_HOST in /opt/bitnami/apps/moodle/htdocs/config.php on line 97
!!! Detected incorrect $CFG->wwwroot in config.php, it must not contain trailing slash.
Please notify server administrator. !!!"
#16 By: Beltran Rueda Borrego, August 8th, 2012 11:29
You can to edit the /opt/bitnami/apps/moodle/htdocs/config.php file and replace the wwwroot option with your domain name. We configured to HTTP_POST to be able to access using any domain. You can find more info at http://wiki.bitnami.com/Applications/BitNami_Moodle#How_to_change_the_default_URL.3f Thanks for posing it I will update the crontab documentation.
#17 By: deverezieaux, August 13th, 2012 14:08
Hi; it's been a couple weeks and I'm wondering if anyone has come up with the correct coding for this task? I've shared my solution on the Moodle forums and as I thought they advised against the reference to PHP, but they aren't sure what the correct path should be in the Bitnami image.
#18 By: kaysa, August 15th, 2012 06:59
Your solution seems ok. Which user is running the cron task? Notice that the users allowed to run that task depends on the permissions of the cron.php (and other related files) and php binary. If the apache user has access to the php binary another solution could be just create that tasks for the apache user (and don't use 'su' in the definition of the task). Regarding changing the config.php to use the IP instead of using the domain, it is likely that from inside the machine the domain name is not found. Maybe adding some entry in /etc/hosts would have also work for you.
#19 By: deverezieaux, September 13th, 2012 10:20
Hi Kaysa, I had to take a break from this specific task while developing coursework for another project.
Unfortunately I can't tell which user is running the cron task. Using sudo php worked, but I don't know why. The folks at the Moodle forums posted a possible solution to idntify the user and create a more reliable cron, but I haven't yet been able to test it. I'll be trying it this weekend.