How to upgrade Nextcloud expecially php version on Ubuntu

Recently, I tried to upload files to VPS through Nextcloud in order to backup my files. But I found the upload speed was quite slow on Windows official client. So I tried to upgrade Nextcloud to the latest version in order to improve its performance. Though the performance did not improve a lot, I learned how to upgrade Nextcloud especially php. In later, I would upload files via webpage for a better performance.

Update: The bottleneck is the network quality between local and server. Now I am using Filezilla to upload files via multiple threads in order to overcome the limit of single thread speed.

Nextcloud provided a great upgrade method in webpage, you just need to follow the instructions in the Administration pages. However, some steps like php upgrade need to be done manually. Now I will demonstrate how to update php from 8.1 which is deprecated to 8.3.

How to upgrade php

Log into your server as root.

1
2
3
4
5
6
7
8
9
apt update
sudo apt install -y software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
sudo apt-cache show php
apt install php8.3
sudo update-alternatives --set php /usr/bin/php8.3
apt install libapache2-mod-php8.3 php8.3-gd php8.3-mysql php8.3-curl php8.3-mbstring php8.3-intl php8.3-gmp php8.3-bcmath php8.3-xml php8.3-imagick php8.3-zip php8.3-imagick imagemagick php8.3-apcu php8.3-redis php8.3-bz2 php8.3-fpm
vim /etc/php/8.3/apache2/conf.d/20-apcu.ini
1
2
extension=apcu.so
apc.enable_cli=1
1
vim /etc/php/8.3/apache2/php.ini # Find and change the following parameters based on your situation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
; Maximum amount of memory a script may consume
; https://php.net/memory-limit
memory_limit = 1G

; Maximum allowed size for uploaded files.
; https://php.net/upload-max-filesize
upload_max_filesize = 100G

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 200

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; https://php.net/post-max-size
post_max_size = 100G

; The amount of memory for interned strings in Mbytes.
;opcache.interned_strings_buffer=8
opcache.interned_strings_buffer=16

; Maximum execution time of each script, in seconds
; https://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
; max_execution_time = 30
max_execution_time = 3600

; Maximum amount of time each script may spend parsing request data. It's a good
; idea to limit this time on productions servers in order to eliminate unexpectedly
; long running scripts.
; Note: This directive is hardcoded to -1 for the CLI SAPI
; Default Value: -1 (Unlimited)
; Development Value: 60 (60 seconds)
; Production Value: 60 (60 seconds)
; https://php.net/max-input-time
; max_input_time = 60
max_input_time = 3600
1
vim /var/www/Nextcloud/config/config.php # add below in the last, which means do maintenance at 22:00 UTC
1
'maintenance_window_start' => 22,
1
vim /etc/apache2/sites-available/your.domain.conf # increase request body size and timeout in apache2
1
2
3
4
5
6
<VirtualHost *:443>
...
LimitRequestBody 107374182400
Timeout 3600
...
</VirtualHost>
1
2
3
a2dismod php8.1
a2enmod php8.3
service apache2 restart

Done. Nextcloud has a very active community. I hope the performance issue on Windows client will be solved one day.

Reference

  1. https://www.php.net/supported-versions.php
  2. https://docs.nextcloud.com/server/30/admin_manual/configuration_server/background_jobs_configuration.html
  3. https://www.reddit.com/r/NextCloud/comments/ye17x5/trying_to_use_occ_getting_occ_command_not_found/
  4. https://www.dedicatedcore.com/blog/upgrade-php-ubuntu/
  5. https://www.reddit.com/r/NextCloud/comments/13cqdr1/php_upgrade_steps/
  6. https://help.nextcloud.com/t/internal-server-error-after-php-upgrade/148262/3
  7. https://www.reddit.com/r/NextCloud/comments/u85klq/error_expected_filesize_of_x_bytes_but_read_from/
  8. https://github.com/nextcloud/server/issues/37695
  9. https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/big_file_upload_configuration.html
  10. https://httpd.apache.org/docs/current/en/mod/core.html#limitrequestbody