Score:1

Can't change PHP version during Drush update database command

cn flag

My server currently is using PHP 7.1 but I need to run PHP 7.4 during my drush commands on one of my sites. The following works for almost all commands:

/path/to/my/php74 ../vendor/bin/drush cr
/path/to/my/php74 ../vendor/bin/drush cim -y

But when I run the update database command I get an error:

/path/to/my/php74 ../vendor/bin/drush updb -y

or:

export DRUSH_PHP=/path/to/my/php74 && /path/to/my/php74 ../vendor/bin/drush updb -y

I get the following error:

In Process.php line 266:
                                                                                                                                                                      
  The command "/home/releases/74/vendor/drush/drush/drush updatedb:status --yes --no-entity-updates --strict=0 --uri=default --root=/ho  
  me/releases/74/web" failed.                                                                                                            
                                                                                                                                                                      
  Exit Code: 255(Unknown error)                                                                                                                                       
                                                                                                                                                                      
  Working directory:                                                                                                                                                  
                                                                                                                                                                      
  Output:                                                                                                                                                             
  ================                                                                                                                                                    
                                                                                                                                                                      
  Warning: Unsupported declare 'strict_types' in /home/releases/74/vendor/phpstan/phpstan/bootstrap.php on line 1                        
                                                                                                                                                                      
  Parse error: syntax error, unexpected ':', expecting ';' or '{' in /home/releases/74/vendor/phpstan/phpstan/bootstrap.php on line 12   
                                                                                                                                                                      
                                                                                                                                                                      
  Error Output:                                                                                                                                                       
  ================                                                                                                                                                    
                            

I'm guessing during the updb command it calls another command but it doesn't retain my php version.

Score:0
ma flag

I was able to run drush cr and drush cim using a specific php version via the command:

/opt/cpanel/ea-php74/root/bin/php ~/public_html/vendor/bin/drush cr and

/opt/cpanel/ea-php74/root/bin/php ~/public_html/vendor/bin/drush cim

This was not working, though, to run drush updb for which I was getting the error mentioned in my other post:

Your Composer dependencies require a PHP version ">= 7.4.0". You are running 7.3.31.

I could make the command line use php7.4 also for drush updb by exporting the PATH variable first with:

export PATH=/opt/cpanel/ea-php74/root/bin:$PATH:$HOME/bin

Then running drush updb normally.

Frank Drebin avatar
us flag
THIS! I was getting crazy because of this and I was always making a silly mistake: I included the whole path to the binary file into PATH and that's wrong. You just have to put in the path, without the binary.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.