I’m experimenting with cron jobs and cpanel, based on what I found in this thread, can someone help me? Which command have the correct formatting?

cd /home/YOUR-USER/YOUR-DOMAIN; /usr/local/bin/php && php flarum schedule:run >/dev/null 2>&1

cd /home/YOUR-USER/YOUR-DOMAIN && /usr/local/bin/php flarum schedule:run

cd /home/YOUR-USER/YOUR-DOMAIN && php flarum schedule:run >> /dev/null 2>&1

    enricodx cd /home/YOUR-USER/YOUR-DOMAIN && /usr/local/bin/php flarum schedule:run works for me.

    14 days later

    luceos Also make sure it runs as the right user, seems to run as root now where it should run as the website user the website runs under www-data or something similar.

    luceos you need to run the command with sudo as the user the site runs as, eg www-data. This applies every time to run flarum commands.

    According to these, why am I editing the crontab for the current user, then? The command crontab -e in the OP implies that I am changing the crontab for the current user, and not for the www-data user (assuming the flarum install directory belongs to the www-data user and under /var/www/flarum directory).

    Should the crontab command be something like, sudo crontab -u www-data -e ?

      mrXmr on many hostings, the default SSH user will be the correct one, so I assume that's why the command in the tutorial was simply given like this.

      It seems like -u is indeed the correct option to modify another user's crontab. Or if your host support it you could switch shell user using the su command before calling ctrontab -e

      12 days later
      a month later

      Hello,
      Unfortunately, I still have a problem with running this schedule. I have an account on shared hosting, and I know that cron generally works.

      An example of another task that works for me:

      /usr/local/bin/php82 /home/MY_USERNAME/domains/MY_DOMAIN/public_html/bin/console cron:daily

      In the case of Flarum, the path looks like this:
      /home/MY_USERNAME/domains/MY_DOMAIN/public_html/flarum/

      I have set up cron in the panel like this:

      • * * * * /home/MY_USERNAME/domains/MY_DOMAIN/public_html/flarum/ && /usr/local/bin/php82 flarum schedule:run

      Unfortunately, it doesn't work. I also tried:

      • * * * * /home/MY_USERNAME/domains/MY_DOMAIN/public_html/ && /usr/local/bin/php82 flarum schedule:run

      Still nothing... I also tried according to the description:

      • * * * * cd /home/MY_USERNAME/domains/MY_DOMAIN/public_html/ && php flarum schedule:run >> /dev/null 2>&1
        and
      • * * * * cd /home/MY_USERNAME/domains/MY_DOMAIN/public_html/flarum && php flarum schedule:run >> /dev/null 2>&1

      Unfortunately, without success... I have been struggling with this for two days now. Please help!

      7 days later
      a month later

      hello. Please explain how to setup corn in cPanel. I'm try 100 times, but it's not work.

        HarishSarker if you run the command without the null redirect part (from cd [...] to [...] schedule:run) in a shell on the server, what is the output? To verify the paths and syntax are correct.

        I don't know whether cPanel has a CRON log output? If not you could also try replacing the null redirect with a redirect to a temporary log file to try to get more information as to what happens when the CRON runs.

        Is there really no username in the /home path? I'm not very familiar with cPanel, maybe the site domain acts as the username, or it's a linux distro where the home directory is not actually used like on other distros.

        11 days later

        IanM * * * * * cd /path-to-your-project && php flarum schedule:run >> /dev/null 2>&1

        Is this still necessary or do extensions use another way to do their crons?

        At least it looks like it's an old solution, because the admin panel doesn't show any info about the cronjob the admin has to create on the linux system and it can be activated without problems or any errors over the admin panel:

        Image

        Image

        And even users can activate a cron without any problems/errors (without the cronjob above):

        Image

          maxmoon fof/drafts does use the Flarum scheduling system, which requires cron (or some other system) to be set up to run the schedule:run command. Clarification on these settings would probably be helpful to have in the extension's settings.

          The admin settings not erroring is because they're simply setting values in the DB, which are used when determining whether to run a job or not in the scheduler.

          The draft autosave is done on the client side (i.e. browser) and so has nothing to do with cron.

            datitisev fof/drafts does use the Flarum scheduling system, which requires cron (or some other system) to be set up to run the schedule:run command.

            datitisev The draft autosave is done on the client side (i.e. browser) and so has nothing to do with cron.

            What exactly does drafts do in the background (on the server side) if drafts autosave is controlled by the client?

            Will it be enough to trigger the scheduler every 3 hours, because every minute sounds a little bit like an overkill to me?

            * */3 * * * cd /path-to-your-project && php flarum schedule:run

              maxmoon That would be publishing scheduled drafts once their time has arrived.

              You should keep the cron job running every minute. The schedule:run command already handles how often the registered schedules by extensions are ran - for example, drafts does have its schedule run every minute, but all it does is retrieve the drafts whose scheduled time has passed, publishes them, and deletes the draft.

              Other extensions may have stuff configured for other intervals. The schedule:run command takes care of that for you, alongside the extension's code. For example, fof/open-collective has its command run every hour instead.

                datitisev drafts does have its schedule run every minute

                Okay, I understand what those scheduled drafts are, now. I am not a fan of it and will deactivate them again and I don't understand why something like this should be useful in a discussion forum? And in many cases, if I don't understand something, I ban it from my life... or at least from my forum.

                Thanks for the good explanation and help 🙂

                Are there other things Flarum does with the cronjob, except of the extensions listed above? Like time based suspension of users?

                  IanM $ crontab -e

                  When i did this it showed this - https://prnt.sc/TVBkjROQ9b-u

                  IanM * * * * * cd /path-to-your-project && php flarum schedule:run >> /dev/null 2>&1

                  When i did this it showed this - bash: ads: command not found

                  so i run this command -

                  IanM cd /path-to-your-project && php flarum schedule:run simply says php flarum ......

                  It showed this - No scheduled commands are ready to run.

                  https://prnt.sc/PsjPcu_iPnGM

                    HD3D yes, the scheduler is an independent functionality to the queue. If any extensions are using the scheduler, it should be set up to run.