Php script names

Php script names

by Martin . -
Number of replies: 3

Hi.

I want to set up scheduled tasks to clear deleted itms ...

Unfortunately I can only run scripts using php5 ... and some (all?) of the scripts seem to require php7. 

Thus running /usr/bin/php /volume1/web/moodle/admin/cli/cron.php 

results in 

Parse error: syntax error, unexpected ':', expecting ';' or '{' in /volume1/web/moodle/lib/classes/component.php on line 1264.

It is not currently possible to change the underlying php version as used by the cli (the web server actually uses php 7.2, it is only the cli limited to 5.6)

My questions are: 

  1. Are all the scripts php7?
  2. If not, which ones can I use (i.e. which are php5) by setting up individual schedules rather than using cron.php which seems to stop at the first error. I am particularly looking to complete 'deletion' of grade book entires ... but there may be other important tasks that I need to do as well ... advice welcome!

Thank you.

Moodle: 3.4.3


Average of ratings: -
In reply to Martin .

Re: Php script names

by Ken Task -
Picture of Particularly helpful Moodlers

Pardon the long response ... but ...

You appear to be hosted with a provider that offers multiple versions of PHP ... some of which have reached end of life and probably shouldn't be used by any customer.

Running the cron script in 3.4.x code does require the higher version of PHP (7.0 ... which also has reached end of life).   The docs at Moodle show how to setup cron on linux systems that are standalone ... ie, not the linux  distro as built/modified by provider.   Thus, the directions that show /usr/bin/php as the path actually is correct on most systems, on your providers system offering multple versions is in-correct.

So ... how to fix ...

From your ssh shell into your account, type: env [ENTER]

Look for a "PATH' line with variables/paths.

I can't share with you what that should look like on your system.   Will say that showed me on a remotely hosted system with a provider that shall remain nameless ... right now ... that the customers environment found the php5 first and thus would not run any of the scripts in moodlecode/admin/cli/ which includes the cron.php script.

The following probably not yours but here's what it looked like on the system upon which I was working:

PATH=/usr/local/cpanel/3rdparty/lib/path-bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/cpanel/composer/bin

The command which php would show /usr/bin/php ... but that was NOT the php for CLI but for the web.

whereis php

if whereis available on your shell, showed other paths ... not included in the environment.

To set up the cron job on that system, had to use the path to the PHP version 7 cli ... which on that system happened to be in /usr/local/bin/

As a test, once you find the paths to the php executables:

Use the full path to php to see the version and which:

php -v on the system in the example here showed this:

PHP 7.1.26 (cgi-fcgi) (built: Jan 14 2019 19:44:52)

That's the PHP for the web ... see the (cgi-fcgi).

However, this one

/usr/local/bin/php -v shows
PHP 7.1.26 (cli) (built: Jan 14 2019 19:44:32) ( NTS )

see the 'cli' above.

So in the path to php in the setup of the cron job on the example system:

/usr/local/bin/php /full/path/to/moodle/code/admin/cli/cron.php

Then worked as expected.

All the scripts in moodlecode/admin/cli/ then all require the path to be:

/usr/local/bin/php ...

Hope that helps.

'spirit of sharing', Ken


Average of ratings: Useful (3)
In reply to Ken Task

Re: Php script names

by Martin . -

Thank you everybody for the help ... particularly Ken ... that was not too long ... and whilst it did not solve the issue directly ... I enjoyed fighting with a CLI ... something I have not had to do for over three decades smile


The solution (for my Synology box)? ... so simple ...

Moodle docs suggest this: /usr/bin/php /path/to/moodle/admin/cli/cron.php

I eventually found that this worked from the CLI (Mac Terminal using SSH): php70 /volume1/web/moodle/admin/cli/cron.php

The time was lost finding that php70 bit !

This works in the CLI ... now to check the scheduler system and see what happens smile

Average of ratings: Useful (1)