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

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

von Joseph Rézeau -
Anzahl Antworten: 6
Nutzerbild von Core developers Nutzerbild von Particularly helpful Moodlers Nutzerbild von Plugin developers Nutzerbild von Testers Nutzerbild von 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

Als Antwort auf Joseph Rézeau

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

von Tim Hunt -
Nutzerbild von Core developers Nutzerbild von Documentation writers Nutzerbild von Particularly helpful Moodlers Nutzerbild von Peer reviewers Nutzerbild von 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
Als Antwort auf Tim Hunt

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

von Joseph Rézeau -
Nutzerbild von Core developers Nutzerbild von Particularly helpful Moodlers Nutzerbild von Plugin developers Nutzerbild von Testers Nutzerbild von 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...

 

Als Antwort auf Joseph Rézeau

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

von Joseph Rézeau -
Nutzerbild von Core developers Nutzerbild von Particularly helpful Moodlers Nutzerbild von Plugin developers Nutzerbild von Testers Nutzerbild von 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?

Als Antwort auf Joseph Rézeau

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

von Joseph Rézeau -
Nutzerbild von Core developers Nutzerbild von Particularly helpful Moodlers Nutzerbild von Plugin developers Nutzerbild von Testers Nutzerbild von Translators