How to run the Moodle CLI commands in a Windows console?

How to run the Moodle CLI commands in a Windows console?

by Joseph Rézeau -
Number of replies: 6
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

How to run the Moodle CLI commands in a Windows console? That is for my moodle localhost (installed under XAMPP).

Could not find the info in the Moodle docs.

Have a nice summer, everyone,

Joseph

Average of ratings: -
In reply to Joseph Rézeau

Re: How to run the Moodle CLI commands in a Windows console?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Well, if you are also using git to track your developments, then that comes with 'Git Bash' console, and you can easily run Moodle CLI commands in there. That definitely works.

If you are not using git, ... well you probably should 😉

Otherwise, you can try them in a normal Windows CMD or Powershell window. That also works. (Well, I just tested PowerShell.)

  1. First make sure that PHP is on the path:
    php -v
    That should output something like:
    PHP 7.3.8 (cli) (built: Jul 30 2019 12:44:06) ( ZTS MSVC15 (Visual C++ 2017) x64 )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies
        with Xdebug v2.8.0beta1, Copyright (c) 2002-2019, by Derick Rethans
  2. If that works, change directory into the root folder of your Moodle.
  3. Then, you can run commands like
    php admin/cli/cfg.php --name=version
Average of ratings: Useful (2)
In reply to Tim Hunt

Re: How to run the Moodle CLI commands in a Windows console?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Tim and thanks for your prompt and helpful reply!

I do have TortoiseGit installed on my Windows 10 local machine, but I had not installed the "Git Bash here" command. I have now re-installed TortoiseGit and enabled the "Git Bash here" command.

Actually, as you said, CLI commands will work as well in the Windows console as in the Git Bash console. The important step I was missing was to put my PHP directory in the Windows path! I've now done that and I can issue CLI commands in my moodle directory root folder, either using the Windows console or git bash.

Just noticed that the docs seems outdated for some commands.

At https://docs.moodle.org/39/en/Administration_via_command_line#Scheduled_tasks it gives this example:

php admin/tool/task/cli/schedule_task.php --list
which returns this error message:
++ admin/tool/task/cli/schedule_task.php is deprecated. Please use admin/cli/scheduled_task.php instead. ++
 
Maybe someone should fix this problem. Maybe there are other changes to make...

 

Average of ratings: Useful (1)
In reply to Joseph Rézeau

Re: How to run the Moodle CLI commands in a Windows console?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

The reason for my original question re the use of Moodle CLI commands in the Windows console was to install all the H5P available content types & libraries in the new Content Bank in Moodle 3.9.

I have successfully done it now, thanks to Tim's help.

But I have a further query. In the docs at https://docs.moodle.org/39/en/Scheduled_tasks#Running_individual_tasks it says:

To be able to run individual scheduled tasks via 'Run now' links on the scheduled tasks page, 'Allow 'Run now' for scheduled tasks' (tool_task | enablerunnow) in Site administration / Security / Site security settings should be enabled AND 'Path to PHP CLI' (pathtophp) in Site administration / Server / System paths should be set.

On my localhost Windows 10 Moodle site I have set Path to PHP CLI to c:\xampp\php and enabled the 'Allow 'Run now' for scheduled tasks'... but still cannot see the "Run now" link on the Scheduled Tasks page.

Why is that?

In reply to Joseph Rézeau

Re: How to run the Moodle CLI commands in a Windows console?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Bump