The history of the home cloud. Part 5 - Update 2019 - PHP 7.2, MariaDB 10.4 and Nextcloud 17

Two years ago, I published a series of articles on the topic of creating a web server based on Debian 8 and running the Nextcloud 11 service on it. A few months later, an addendum appeared containing “differential” information on installing Nextcloud 13 on Debian 9. At the end of 2018, I simply upgraded Debian and Nextcloud and didn't run into any unusual or interesting issues. The update at the end of 2019 was already more interesting and worth writing about.

The history of the home cloud. Part 5 - Update 2019 - PHP 7.2, MariaDB 10.4 and Nextcloud 17

This article will be primarily useful to those who, according to the instructions of the last four articles, “assembled” Nextcloud 13 on Debian 9 for themselves (I send greetings to a dozen of my Nextcloud subscribers, especially those for whom this was the first experience in the world of Linux). For those who are going to make a service from scratch, I advise you to take the first four articles of this series as a basis, adjusted for the current versions of Debian 10 and Nextcloud 17. For experienced Linux users, the article can take some place between “trivial and useless” and “not bad, cheat sheet all-in-one-place.

Table of contents

Part 1: Setting up a Debian environment for everyday use
Part 2: Building a Server - Configuring LAMP on Debian
Part 3. Creating a personal cloud - installing and configuring Nextcloud
Part 4 - Update 2018 - Debian 9 and Nextcloud 13
Part 5 - Update 2019 - PHP 7.2, MariaDB 10.4 and Nextcloud 17

Chapter Quick Navigation

foreword
Debian update
Updating PHP to version 7.2
Upgrading MariaDB to version 10.4
Nextcloud update to version 17
Afterword

foreword

Initially, I wanted to install and configure Nginx on Debian 10, on top of which the current Nextcloud 17 would be installed without any problems. But for all this I could not choose the time, so this article is a set of instructions for updating Nextcloud from 13 to the current version 17 with a preliminary preparing the web server.

To begin with, we need to explain why radical changes were required on the web server side. Our server is based on the current and supported Debian 9. You can simply update the operating system and all web server components will receive at least security updates. Everything would be great if we continued to use Nextcloud 13 or upgraded only to version 14. But Nextcloud 13 is no longer supported, and support for the 14th version is on the wane. Starting with version 15, Nexctcloud will offer to convert the database to a big int to support four-byte encoding, and with MariaDB 10.1, this will be very problematic. Nexctcloud 17 requires PHP 7.1-7.3, while Debian 9 only contains version 7.0 in its native repositories. It would be more correct, in terms of reliability and predictability, to upgrade to the penultimate version of Nextcloud, but in a couple of years I was so confident in the reliability of this service that I wanted to upgrade to the latest version and upgrade the web server with a backlog for the future. Therefore, to upgrade to Nexctcloud 17, it is optimal to upgrade MariaDB to the current stable version 10.4, and PHP to 7.2. It is 7.2, not the current 7.4. The fact is that Nextcloud 13 requires PHP 5.6, 7.0 - 7.2, and Nexctcloud 17 requires PHP 7.1 - 7.3. It is convenient to use PHP 7.2 in order to minimize upgrade actions. The Apache server does not need to be updated - just install the security updates distributed by the Debian Support team. But for MariaDB and PHP updates, you will have to connect external repositories.

When I first got acquainted with Nextcloud, I updated it “by hand”: from the console, a special command put the site into maintenance mode, manually downloaded and unpacked the archive with the new version of the site, updated the files, and started the update procedure. Such an update usually led to the expected results, although I was not lazy to make a backup copy of the site, database and user data. But automatic updating sometimes led to all sorts of surprises. But that was a long time ago, the stability of the engine has improved a lot since then, and this time I made updates exclusively through the web interface. True, it was still not possible to get out of the command line. With an iterative update to each new version, various warnings and notifications will appear in the control panel, which will need to be “removed” by meaningfully executing commands on the command line. You can not do this - the service will still work. Although this approach is fundamentally wrong, Nextcloud worked for me in this mode for 3 months before I purposefully dealt with the questions that arose.

Debine update

Stop the web server:

# service apache2 stop


And update:

# apt-get update
# apt-get dist-upgrade


After the update, you can check the OS version and do a control reboot to make sure that everything starts normally after the update:

# cat /etc/debian_version
# reboot


Updating PHP to version 7.2

Stop the web server:

# service apache2 stop


Add PPA certificate and keys, PHP repository:

# apt install ca-certificates apt-transport-https
# wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add -
# echo "deb https://packages.sury.org/php/ stretch main" | tee /etc/apt/sources.list.d/php.list


When removing the old version of PHP 7.0, phpmyadmin will also be removed, since we will clean up the “traces” of the removed packages using autoremove. This will not cause any particular difficulties, since no special settings have been made for phpmyadmin and installing it again will not be any problem.

# apt-get purge php7*
# apt-get --purge autoremove
# apt-get update
# apt-get install php7.2 phpmyadmin


Installing modules required for Nextcloud 17:

# apt-get install php7.2-mysql php7.2-curl php7.2-xml php7.2-gd php7.2-json php7.2-mbstring php7.2-zip php7.2-intl
# apt-get install php-memcached php-apcu php-redis php-imagick


[ This text written specifically for the site habr.com author AlexanderS.
A link to the source is optional, but mentioning it is highly recommended! ]

Check the PHP version, start the web server and check if Nextcloud works:

# php -v
# service apache2 start


Upgrading MariaDB to version 10.4

The project website has interesting page, where you need to specify your OS, its release and select the version of the database. Once selected, code will be generated to add the repository.

Stop the web server:

# service apache2 stop


Add repository and update packages:

# apt-get install software-properties-common dirmngr
# apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
# add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mariadb.mirror.iweb.com/repo/10.4/debian stretch main'
# apt-get update


When installing MariaDB, the package manager will correctly remove the previous version and install the new one, all databases will be preserved. However, it is certainly recommended to make a backup copy of the Nextcloud database.

Install MariaDB and run the update procedure:

# apt-get install mariadb-server
# mysql_upgrade u root -p


After entering the password, MariaDB will be updated and you can configure it by following instructions from the second part:

# mysql_secure_installation


We start the web server and check the functionality of Nextcloud:

# service apache2 start


Nextcloud update to version 17

To start the update, you need to log in to the service under an administrative account, go to the settings and open the "General settings" in the administrative section. Nextcloud shows the installed version and the version available for updating, which can be launched by clicking the "Open update window" button. Upon initiation, Nextcloud makes a backup copy, downloads and checks the integrity of the update files, turns on maintenance mode, and updates the files. The next question is “Keep maintenance mode active”? Here you need to be careful. A positive response will leave the site in maintenance mode - it is assumed that the administrator knows what to do next and will do it manually. Otherwise, Nextcloud will do everything by itself, so click the "No" button to continue.

Updates are performed iteratively. First, Nextcloud 13.x will upgrade to the latest version of the 14.x branch. After that, you will need to go back to the admin center and run the update, now from 14.x to 15.x. And so on until the last possible up-to-date version is reached. After each update, the "General Settings" page in the administrative section will display a list of suggestions and problems that have arisen, as well as recommendations for solving them. Below we will talk about what will need to be done after each update.

Before update

On the latest versions of Nextcloud, it is recommended to enable PHP OPcache to improve performance. It is strange that I somehow missed this moment a couple of years ago, since OPcache appeared back in PHP 5. In /etc/php/7.2/apache2/php.ini, you need to uncomment and edit the following parameters:

opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
pcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1


Update 13.x -> 14.x

Restoring table indexes:

# sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices


Update 14.x -> 15.x

Prepare the nextcloud database to enable XNUMX-byte encoding:

# mysql -u root -p
MariaDB [(none)]> ALTER DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
MariaDB [(none)]> quit


Enable support for XNUMX-byte encoding in Nextcloud:

# sudo -u www-data php /var/www/nextcloud/occ config:system:set mysql.utf8mb4 --type boolean --value="true"


Converting tables:

# sudo -u www-data php /var/www/nextcloud/occ maintenance:repair


Restoring lost table indexes:

# sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices


Convert table indexes to bigint:

# sudo -u www-data php /var/www/nextcloud/occ db:convert-filecache-bigint


Update 15.x -> 16.x

Restoring lost table indexes:

# sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices


Convert table indexes to bigint:

# sudo -u www-data php /var/www/nextcloud/occ db:convert-filecache-bigint


Update 16.x -> 17.x

No additional action is required.

Afterword

According to these instructions, the virtual machine was updated with Nextcloud 13. Using a virtual machine allows you not to make backup copies of Nextcloud files and its database, since in case of problems you can simply return the previously saved virtual machine file and start over. However, this does not apply to the user data folder, which I also recommend backing up along with the Nextcloud virtual machine. In my case, the “cloud” is used as a remote folder with automatic versioning, and with the synchronization direction “only there”, and losing this data was not critical for me - I would just have to do the synchronization again for several hours. Despite my disregard for the time-honoured “save just in case” rule, the upgrade went smoothly and all customers got their Nextcloud 17 up and running without issue. I’m impressed Frank Karlitschek – you and your team are doing a great job!

After the update, I decided to clean up user data, which, judging by the statistics, occupied under two terabytes. I didn’t have so much operational data - most of the volume was occupied by version files and deleted files. The problem I encountered was that for one user there was so much deleted data (it’s not even about the volume, but the quantity - there are a lot of small files) that Nextcloud could not display them in the web interface. After reading the administration guide, I found a solution through the command line. Perhaps someone will find it useful.

To clean up deleted files for user user:

# sudo -u www-data php /var/www/nextcloud/occ trashbin:cleanup user


To clean up user version files:

# sudo -u www-data php /var/www/nextcloud/occ versions:cleanup user

Return top, top.

The history of the home cloud. Part 5 - Update 2019 - PHP 7.2, MariaDB 10.4 and Nextcloud 17
Text version: 1.1.1.
Date of first publication: 15.01.2020/XNUMX/XNUMX.
Date of last revision: 15.01.2020/XNUMX/XNUMX.

Update log1.1.1 [15-01-2020] Correction of typos.

1.1.0 [15-01-2020] Fixed nexcloud database preparation code to enable XNUMX-byte encoding.

1.0.0 [15-01-2020] First version.

Source: habr.com