-3

How do you run Drupal's drush cron jobs when your server has a newer PHP version installed from Software Collections?

The server is running Scientific Linux 7, which comes with PHP 5.4, but we need, and have installed, PHP 7.1 using the Software Collections rh-php71 package. Apache and therefore Drupal work fine with PHP 7.1, but we also need to add the drush cron jobs to our crontab, and ensure that drush is using the newer version of PHP when it does so. We have tested to see if drush (we have drush 8.1.10 installed) will run with the default PHP 5.4, just in case, but the cron jobs understandably crash with errors.

We have tried to test the cron command (in the way that you would normally attempt to run a command within a scl wrapper), by running the following as root:

scl enable rh-php71 drush cron -r /data/webs/www/siteroot

but this will not run, returning the error:

Unable to open /etc/scl/conf/drush!

Further testing (in a terminal) shows that we can however successfully run the drush command within a subshell which is within a scl wrapper:

scl enable rh-php71 bash
drush cron -r /data/webs/www/siteroot
exit

Is there some way that we can run the necessary drush commands just as a 'one-liner' in the crontab, or do I have no option but to have to create a separate shell script containing the above commands, and call that as the cron job command instead?

(I have also asked this question on Unix.SE, as it seems more of a Linux question than a Drupal one as such, but have had no responses.)

  • First you need to explain what scl enable rh-php71does? Does it set some environmental variables or ... You can tell Drush to use a specific version of PHP with DRUSH_PHP - see drupal.stackexchange.com/a/242258/24060 – hansfn May 7 at 11:19
  • Thanks, that's useful to know about DRUSH_PHP. I don't know if that would work in this case as I'm afraid I don't know exactly what the scl wrapper actually does (but I think it involves an element of heavy lifting as regards to reconfiguring the environment when invoked)? – dave559 May 7 at 11:41
  • You might not need all the changes introduced by scl enable rh-php71. Running env or just echo $PATH after scl enable rh-php71 bash should tell you enough. Anyway, the problem could be related to the user running scl. Cron is often using root. Does your scl wrapper work if you run it as root. And so on until you understand what the problem is :-) – hansfn May 7 at 12:03
0

After reading a more technical section of the Software Collections guide it turns out that when trying to run a command which has arguments within a scl wrapper, you need to enclose the command in single quotes or separate it from the wrapper part of the line with two minus signs:

If you are running a command with multiple arguments, remember to enclose the command and its arguments in quotes:

scl action software_collection_1 software_collection_2 'command --argument'

Alternatively, use a -- command separator to run a command with multiple arguments:

scl action software_collection_1 software_collection_2 -- command --argument

My drush command runs successfully now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.