Score:0

Issues with CRON job executing on Ubuntu 20.04 with PHP 7.4 FPM

cn flag

I am having issues properly setting up the following CRON job to automate backups on my client's website.

The site is Joomla-based and I am using Akeeba Backup to handle the backups. The recommendations for the command-line CRON jobs are as follows:

Use the following command in your host's CRON interface: /path/to/php /var/www/domain.com/cli/akeeba-backup.php

Remember to substitute /path/to/php with the real path to your host's PHP CLI (Command Line Interface) executable. Do remember that you must use the PHP CLI executable; the PHP CGI (Common Gateway Interface) executable will not work with our CRON scripts. If unsure what this means, please consult your host. They are the only people who can provide this information.

domain.com used as an example

I have CRON installed and running on Ubuntu 20.04.

The following code is in crontab -e

0 3 * * * /usr/bin/php7.4 /var/www/domain.com/cli/akeeba-backup.php --profile=1 --description="Full automated backup"

The site is running PHP 7.4 with FPM installed.

When I run which php the following is returned: /usr/bin/php

When I run ls -l /usr/bin/php the following is returned: lrwxrwxrwx 1 root root 21 Aug 31 18:09 /usr/bin/php -> /etc/alternatives/php

When I run ls -l /etc/alternatives/php the following is returned: lrwxrwxrwx 1 root root 15 Aug 31 18:53 /etc/alternatives/php -> /usr/bin/php8.0

As this shows version 8.0 instead of 7.4, which the site is using, does this mean the CRON job should be using version 8 instead.

Sample log output from /var/log/syslog

Oct 1 11:39:01 domain CRON[38538]: (root) CMD ( [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)

Any help is greatly appreciated.

Score:0
it flag

Jobs run through cron aren't run in the same runtime environment that you have on your desktop. None of your PATH changes, or other environment variable settings from ~/.bashrc are automatically propagated to your cron job. For example, there's no $DISPLAY, so GUI programs need special treatment (read man xhost).

One can set environment variables for all one's cron jobs in the crontab file Read man 5 crontab.

Look at the results of echo "=== id ===";id;echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias in each of your environments.

By "each" I mean cron and Desktop, you could leave batch and "non-GUI terminal" for later, if you're curious.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.