matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.91k stars 2.65k forks source link

[Bug] Update to 5.1.2 causes console error, requires config.ini.php to be writeable #22633

Closed mikkeschiren closed 1 month ago

mikkeschiren commented 1 month ago

What happened?

Starting the database upgrade process now. This may take a while, so please be patient.

    *** Update ***

    Database Upgrade Required

    Your Matomo database is out-of-date, and must be upgraded before you can continue.

    Matomo database will be upgraded from version 5.1.1 to the new version 5.1.2.

    The database upgrade process may take a while, so please be patient.

  Executing ./console config:set --section="database" --key="collation" --value="utf8mb3_general_ci"...
    [X] Critical Error during the update process:

    * /var/www/html/core/Updates/5.1.2-rc1.php:
    Error trying to execute the migration './console config:set --section="database" --key="collation" --value="utf8mb3_general_ci"'.
    The error was: The Matomo configuration file (config/config.ini.php) is not writable, some of your changes might not be saved.  Please change permissions of the config file to make it writable.

    The above is the core error message. It should help explain the cause, but if you require further help please:

    * Check the [ Matomo FAQ ] which explains most common errors during update.
    * Ask your system administrator - they may be able to help you with the error which is most likely related to your server or MySQL setup.

    If you are an advanced user and encounter an error in the database upgrade:

    * identify and correct the source of the problem (e.g., memory_limit or max_execution_time)
    * execute the remaining queries in the update that failed
    * manually update the `option` table in your Matomo database, setting the value of version_core to the version of the failed update
    * re-run the updater (through the browser or command-line) to continue with the remaining updates
    * report the problem (and solution) so that Matomo can be improved
ERROR     [2024-10-01 08:54:56] 1  Uncaught exception: /var/www/html/plugins/CoreUpdater/Commands/Update.php(267): Matomo could not be updated! See above for more information. [Query: , CLI mode: 1]

In Update.php line 267:

  Matomo could not be updated! See above for more information.

core:update [--yes] [--skip-cache-clear]

What should happen?

It should be possible to run core update, without writing to config.ini.php

How can this be reproduced?

Make config.ini.php not writeable. Make sure you are running 5.1.1. Update to 5.1.2

Matomo version

5.1.2

PHP version

8.1.30

Server operating system

No response

What browsers are you seeing the problem on?

No response

Computer operating system

No response

Relevant log output

No response

Validations

mikkeschiren commented 1 month ago

Also - I can see that the core update file was named 5.1.2-rc1.php in 5.1.2, and that it has been renamed to 5.2.0-b2.php. I am not sure why this has been done.

mikkeschiren commented 1 month ago

the issue itself could be eeasily solved by setting the config in before updating, and keeping the write protection, but would like to know the need to have it writeable in the first place.

mikkeschiren commented 1 month ago

Also see #22634.

michalkleiner commented 1 month ago

Also - I can see that the core update file was named 5.1.2-rc1.php in 5.1.2, and that it has been renamed to 5.2.0-b2.php. I am not sure why this has been done.

Those are two different update files for two different minor version streams. They may have the same content, but are for different versions.

mikkeschiren commented 1 month ago

Yes that I do understand, but why this practice? Wouldn't it be better to keep both, as they contain the same thing, the impact would be none. I am not really keen on that it is named rc1 in a tagged release either :)

sgiehl commented 1 month ago

We had to add/rename the update script to ensure it's executed on every install. Those on the stable channel might update to 5.1.2, but those on beta channel might already update to directly 5.2.0-b2. We could also have kept both files, but it's actually useless to perform the same update twice.

This is btw. not the first update script that tries to change the config and it might not be the last. In some cases it's necessary to write certain values to the config during in an update. I would suggest you to give at least the user running console core:update write permission to the config.

But we could also improve our process so updating the config is only performed if the config does not yet have the correct value. This would at least allow to manually set the config in order to be able to update without a failure.

mikkeschiren commented 1 month ago

Just a FYI: In our environment we do not allow any writing to the config file, as we see it as a potential security risk. But that is for us to handle.

sgiehl commented 1 month ago

But we could also improve our process so updating the config is only performed if the config does not yet have the correct value. This would at least allow to manually set the config in order to be able to update without a failure.

I've just checked the update script again. It will only try to set a config value if none is present yet. So performing the updating after manually setting the config should not result in an error. So guess there is nothing left to do.