Skip to content

Allow upgrades when HOME is read-only #195

@kenahoo

Description

@kenahoo

I originally asked this as a question at Stack Overflow: https://civicrm.stackexchange.com/questions/48137/upgrade-5-66-0-5-66-2-fails-with-permission-error .

I'm using CiviCRM with Wordpress 6.5.3 and MySQL 5.7.44.

I'm attempting to upgrade my CiviCRM from 5.66.0 to 5.66.2. When I get to the DB upgrade stage, when I hit /wp-admin/admin.php?page=CiviCRM&q=civicrm/upgrade&reset=1 -> Upgrade Now -> OK, I just see an empty progress bar and the message [Executed: undefined].

If I switch to the command-line cv (version v0.3.48), and turn on maximum debugging output, I see this:

singersin@s483:~/www/wp$ cv upgrade:db -vvv

Box Requirements Checker
========================

> Using PHP 8.1.28
> PHP is using the following php.ini file:
  /home/singersin/www/wp/php.ini

> Checking Box requirements:
  ✔ The application requires a version matching ">=7.3.0".
  ✔ The application requires the extension "json".
  ✔ The package "psy/psysh" requires the extension "json".
  ✔ The package "nikic/php-parser" requires the extension "tokenizer".
  ✔ The package "psy/psysh" requires the extension "tokenizer".
  
                                                                                                                                                                                                                      
 [OK] Your system is ready to run the application.                                                                                                                                                                    
                                                                                                                                                                                                                      

[BootTrait:debug] Start
[BootTrait:debug] Attempting to set verbose error reporting
[BootTrait:debug] Call standard cv bootstrap
[Bootstrap:debug] Options: {
    "dynamicSettingsFile": "phar:///home/singersin/private/bin/cv/lib/settings_location.php",
    "env": "CIVICRM_SETTINGS",
    "prefetch": true,
    "settingsFile": null,
    "search": true,
    "cmsType": null,
    "httpHost": "",
    "output": {}
}
[Bootstrap:debug] Find settings file
[Bootstrap:debug] Load supplemental configuration for "/home/singersin/www/wp/wp-content/uploads/civicrm/civicrm.settings.php"
[Bootstrap:notice] Find CMS root for "/home/singersin/www/wp"
[Bootstrap:notice] Found "wp" in "/home/singersin/www/wp"
[Bootstrap:notice] Simulate web environment in CLI
[Bootstrap:debug] Load settings file "/home/singersin/www/wp/wp-content/uploads/civicrm/civicrm.settings.php"
[Bootstrap:notice] Initialize class loader
[Bootstrap:notice] Call core bootstrap
[Bootstrap:debug] Finished
[BootTrait:debug] Call core bootstrap
[BootTrait:debug] Call CMS bootstrap
[BootTrait:debug] Set active MySQL timezone
[BootTrait:debug] Finished
[PHP Warning] mkdir(): Permission denied at phar:///home/singersin/private/bin/cv/src/Command/UpgradeDbCommand.php:137

In UpgradeDbCommand.php line 138:
                                                                         
  [RuntimeException]                                                     
  Failed to initialize upgrade data folder: /home/singersin/.cv/upgrade  
                                                                         

Exception trace:
  at phar:///home/singersin/private/bin/cv/src/Command/UpgradeDbCommand.php:138
 Civi\Cv\Command\UpgradeDbCommand->getUpgradeFile() at phar:///home/singersin/private/bin/cv/src/Command/UpgradeDbCommand.php:47
 Civi\Cv\Command\UpgradeDbCommand->execute() at phar:///home/singersin/private/bin/cv/vendor/symfony/console/Command/Command.php:127
 Cvphar\Symfony\Component\Console\Command\Command->run() at phar:///home/singersin/private/bin/cv/vendor/symfony/console/Application.php:637
 Cvphar\Symfony\Component\Console\Application->doRunCommand() at phar:///home/singersin/private/bin/cv/vendor/symfony/console/Application.php:190
 Cvphar\Symfony\Component\Console\Application->doRun() at phar:///home/singersin/private/bin/cv/src/Application.php:67
 Civi\Cv\Application->doRun() at phar:///home/singersin/private/bin/cv/vendor/symfony/console/Application.php:101
 Cvphar\Symfony\Component\Console\Application->run() at phar:///home/singersin/private/bin/cv/src/Application.php:33
 Civi\Cv\Application::main() at phar:///home/singersin/private/bin/cv/bin/cv:28
 require() at /home/singersin/private/bin/cv:14

I'm assuming this is because I don't have permission to create directories in $HOME (the site's hosting provider doesn't allow it):

$ ls -ld ~
drwxr-x---+ 15 root singersin 4096 Mar  9  2020 /home/singersin

Can I specify a different temporary directory for it to perform its work somehow? Trying HOME=$HOME/private/tmp cv upgrade:db didn't work, it still tried to create .cv/upgrade in the original non-writeable location. This seems to be because PHP in general doesn't allow overriding HOME:

$ HOME=foo BAR=baz php -r '$home=getenv("HOME"); $bar=getenv("BAR"); echo("[$home;$bar]\n");'
[/home/singersin;baz]

CGI binaries will let me override HOME, but cv refuses to run from a CGI binary:

$ HOME=$HOME/private/tmp php81.cgi bin/cv
Content-type: text/html


The application may only be invoked from a command line, got "cgi-fcgi"

I'm also wondering if there's some place I can find the DB update steps and just run them manually, is that an option? How can I find those SQL statements?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions