The History of Creating a Home Cloud. Part 5. Update 2019 – PHP 7.2, MariaDB 10.4, and Nextcloud 17

Two years ago, I published a series of articles about setting up a web server based on Debian 8 and launching the Nextcloud 11 service on it. A few months later, an addendum was released, containing 'differential' information about installing Nextcloud 13 on Debian 9. At the end of 2018, I simply upgraded Debian and Nextcloud and did not encounter any unusual or interesting issues. The upgrade at the end of 2019 was much more interesting, and it's worth writing about.

The History of Creating a Home Cloud. Part 5. Update 2019 – PHP 7.2, MariaDB 10.4, and Nextcloud 17

This article will primarily be useful to those who followed the instructions from the past four articles and 'built' Nextcloud 13 on Debian 9 (shout out to my ten subscribers on the topic of Nextcloud, especially those for whom this was their first experience in the Linux world). For those planning to create a service from scratch, I recommend using the first four articles in this series, with adjustments for the current versions of Debian 10 and Nextcloud 17. For experienced Linux users, the article may occupy a space somewhere between 'trivial and useless' and 'not bad, a one-stop cheat sheet.'

Table of Contents

Part 1. Configuring the Debian Environment for Everyday Use
Part 2. Creating a Server β€” Setting Up 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

Quick Navigation in the Chapter

Preface
Updating Debian
Upgrading PHP to Version 7.2
Upgrading MariaDB to Version 10.4
Upgrading Nextcloud to Version 17
Afterword

Preface

Initially, I wanted to install and configure Nginx on Debian 10, on top of which the current Nextcloud 17 would be easily installed. However, I couldn't find the time for all of this, so this article serves as a set of instructions for upgrading Nextcloud from 13 to the current version 17 with prior preparation of the web server.

To begin with, it is necessary to explain why radical changes were needed on the web server side. Our server is based on the current and supported Debian 9. One could simply update the operating system, and all web server components would at least receive security updates. It would be wonderful if we continued using Nextcloud 13 or upgraded only to version 14. However, Nextcloud 13 is no longer supported, and support for version 14 is 'sunsetting'. Starting with version 15, Nextcloud will suggest converting the database to big int for support of four-byte encoding, and doing this with MariaDB 10.1 could be quite problematic. Nextcloud 17 requires PHP 7.1-7.3, while Debian 9 in its native repositories contains only version 7.0. From a reliability and predictability standpoint, it would be more appropriate to upgrade to the penultimate version of Nextcloud, but over the past few years, I have become so confident in the reliability of this service that I wanted to upgrade to the latest version and modernize the web server for future needs. Therefore, to upgrade to Nextcloud 17, it is optimal to upgrade MariaDB to the current stable version 10.4 and PHP to 7.2. Specifically, 7.2, not the current 7.4. The reason is that Nextcloud 13 requires PHP 5.6, 7.0 - 7.2, while Nextcloud 17 requires PHP 7.1 - 7.3. Using PHP 7.2 is convenient for minimizing update actions. The Apache server will not need to be updated β€” it is sufficient to install the security updates provided by the Debian support team. However, for updating MariaDB and PHP, it will be necessary to connect external repositories.

When I first got acquainted with Nextcloud, I would update it manually: using a special command in the console, the site would be switched to maintenance mode, I would manually download and unpack the archive with the new version of the site, update the files, and run the update procedure. Such updates usually led to the expected results, although I didn't hesitate to back up the site, database, and user data. Automatic updates, however, sometimes led to various surprises. But that was a long time ago; the stability of the engine has greatly increased since then, and this time I carried out updates exclusively through the web interface. However, I still couldn't avoid the command line. During iterative updates, various warnings and notifications would appear in the control panel for each new version that needed to be addressed by executing commands in the command line. One could choose not to do thisβ€”the service would still work. Although this approach is fundamentally incorrect, my Nextcloud operated in this mode for 3 months before I purposefully addressed the arising questions.

Updating Debian

Stopping the web server:

# service apache2 stop


And updating:

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


After the update, you can check the OS version and perform a control reboot to ensure everything starts normally after the update:

# cat /etc/debian_version
# reboot


Upgrading PHP to Version 7.2

Stopping the web server:

# service apache2 stop


Adding the 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 PHP 7.0 version, phpMyAdmin will also be removed, as we will clean up the 'traces' of removed packages using autoremove. This won't pose any particular difficulties since no special configurations were made for phpMyAdmin and reinstalling it won't be a problem.

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


Installing the 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 is written specifically for the site habr.com by the author AlexanderS.
A link to the source is not mandatory, but its mention is highly desirable! ]

Checking the PHP version, starting the web server, and checking the functionality of Nextcloud:

# php -v
# service apache2 start


Upgrading MariaDB to Version 10.4

The project website has an interesting page, where you need to specify your OS, its release, and choose the database version. After selection, a code will be generated for adding the repository.

Stopping the web server:

# service apache2 stop


Adding the repository and updating 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, while all databases will be preserved. However, it is recommended to create a backup of the Nextcloud database.

Let's install MariaDB and start the update procedure:

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


After entering the password, MariaDB will update and you will be able to configure it by following the instructions from the second part:

# mysql_secure_installation


Start the web server and check the functionality of Nextcloud:

# service apache2 start


Upgrading Nextcloud to Version 17

To initiate the update, you need to log in to the service using an administrative account, navigate to the settings, and open 'General settings' in the admin section. Nextcloud displays the installed version and the version available for update, which can be started by clicking the 'Open update window' button. After initiation, Nextcloud creates a backup, downloads and checks the integrity of the update files, enters maintenance mode, and updates the files. Then, there will be a question 'Keep maintenance mode active'? Here you need to be careful. A positive answer will keep the site in maintenance mode β€” it is assumed that the administrator knows what to do next and will do it manually. Otherwise, Nextcloud will handle everything itself, so to continue, click the 'No' button.

Updates are performed iteratively. First, Nextcloud 13.x will update to the latest version of the 14.x branch. After that, you will need to return to the admin center and start an update, now from 14.x to 15.x. And so on until the latest possible version is reached. After each update, a list of suggestions and issues encountered, along with recommendations for their resolution, will be displayed on the 'General settings' page in the admin section. Below, we will discuss what needs to be done after each update.

Before the update

In the latest versions of Nextcloud, it is recommended to enable PHP OPcache for improved performance. It's strange that I overlooked this a couple of years ago since OPcache has been available since 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
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1


Update 13.x -> 14.x

Restore the indexes of the tables:

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


Update 14.x -> 15.x

Preparing the Nextcloud database for enabling four-byte encoding:

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


Enabling four-byte encoding support in Nextcloud:

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


Transforming 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


Converting table indexes to bigint:

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


Upgrade 15.x -> 16.x

Restoring lost table indexes:

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


Converting table indexes to bigint:

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


Upgrade 16.x -> 17.x

No additional actions are required.

Afterword

Following this guide, the virtual machine with Nextcloud 13 was upgraded. Using a virtual machine eliminates the need to back up Nextcloud files and its database, as in case of issues, you can simply restore a previously saved virtual machine file and start over. However, this does not apply to the folder with user data, which I also recommend backing up along with the virtual machine with Nextcloud. In my case, the 'cloud' is used as a remote folder with automatic versioning, with synchronization direction set to 'upload only', and I did not consider losing this data critical β€” I would just need to redo the synchronization for a few hours. Despite my disregard for the established life rule 'backup just in case', the upgrade went smoothly, and all clients also worked without issues with Nextcloud 17. I'm impressed, Frank Karlitschke β€” you and your team are doing a great job!

After the upgrade, I decided to clean up the user data, which, according to statistics, occupied about two terabytes. I didn't have that much operational data β€” most of the volume was taken up by version files and deleted files. The problem I encountered was that for one user, there were so many deleted files (it wasn't about the volume, but rather the number β€” a lot of small files) that Nextcloud could not display them in the web interface. After studying the administration guide, I found a solution via the command line. This might be useful for someone.

To clean up deleted files for user user:

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


To clean up version files for user user:

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

Return to the beginning, to the contents.

The History of Creating a Home Cloud. Part 5. Update 2019 – PHP 7.2, MariaDB 10.4, and Nextcloud 17
Text version: 1.1.1.
Date of first publication: January 15, 2020.
Date of last edit: January 15, 2020.

Change log1.1.1 [15-01-2020]
Fixed typos.

1.1.0 [15-01-2020]
Corrected the database preparation code for Nextcloud to enable four-byte encoding.

1.0.0 [15-01-2020]
First version.

Source: habr.com

Buy reliable website hosting with DDoS protection, VPS VDS servers πŸ”₯ Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster