-
Notifications
You must be signed in to change notification settings - Fork 45
Upgrade to PHP 8.2 with Nginx
❗ ❗ ❗ PHP 8.2 is no longer the recommended version for Nextcloud. ❗ ❗ ❗
Follow the PHP 8.3 upgrade guide if you have Nextcloud 28 or later
- This tutorial was developed for and tested with DietPi 8.23.3 based on Debian Bullseye on a RaspberryPI.
- If you're using DietPi based on Debian Bookworm, you should already have PHP 8.2 installed
- This tutorial only works if you use "Nginx" as webserver.
- DietPi may behave differently on other systems.
-
Nextcloud 26 is required before upgrading to PHP 8.2.
- Since Nextcloud 26 doesn't work with PHP 7.4, you should follow our previous PHP 8.1 upgrade guide if you haven't already.
- Upgrading PHP may affect other software on your DietPi that uses PHP. Make sure it is compatible before you upgrade
- Make sure to make a backup of your entire DietPi Instance (config, data, etc.) before you do this.
After you have read the information above and ensured you're ready to start, follow the steps below to upgrade your DietPi to PHP 8.2 with the Nginx webserver.
- If you're using SSH, log in with
ssh root@<your dietpi ip>
. - If you're directly on the device, use
sudo su
With the following commands you will add the PHP 8.2 repository from deb.sury.org to your DietPi:
ℹ If you already followed the previous PHP 8.0 or PHP 8.1 upgrade guides, this may not be necessary.
- Install dependencies
apt-get -y install apt-transport-https lsb-release ca-certificates curl
- Download the public key and add the repository
curl -sSL -o /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
- Update the list of available software
apt-get update
Now install PHP 8.2 on your DietPi with the following commands:
- Remove conflicting packages
apt-get -y remove php-apcu php-igbinary php-redis
- Install PHP 8.2
apt-get -y install php8.2-common php8.2-fpm php8.2-cli php8.2-opcache php8.2-apcu php8.2-mysql php8.2-xml php8.2-zip php8.2-mbstring php8.2-gd php8.2-curl php8.2-redis php8.2-intl php8.2-bcmath php8.2-gmp php8.2-bz2 php8.2-imagick php8.2-igbinary php8.2-readline php8.2-phpdbg libmagickwand-dev imagemagick
- If you have installed optional php modules for specific Nextcloud apps, you need to upgrade them too.
Here is a list for the apps mentioned in the Nextcloud docs:
- LDAP integration:
apt-get install -y php8.2-ldap
- External Storage with SMB/CIFS integration:
apt-get install -y php8.2-smbclient
- LDAP integration:
You need to copy and edit the php-fpm configuration for PHP 8.2.
- Copy the existing configuration file from PHP 7.4 to 8.2
cp /etc/php/7.4/fpm/pool.d/www.conf /etc/php/8.2/fpm/pool.d/www.conf
- Open the configuration file with nano to edit it
You can use
CTRL
+w
to search in the file, withCRTL
+o
you can save the changed file and withCRTL
+x
you can close the editor.nano /etc/php/8.2/fpm/pool.d/www.conf
- Find the following line:
and replace it with this line:
listen = /run/php/php7.4-fpm.sock
listen = /run/php/php8.2-fpm.sock
- Now save the file with
CRTL
+o
and exit the editor withCRTL
+x
- Enable the image magick module (Errors related to PHP 7.4 can be ignored)
phpenmod imagick
- Symlink DietPi PHP 7.4 configuration to PHP 8.2
ln -s /etc/php/7.4/mods-available/dietpi-nextcloud.ini /etc/php/8.2/mods-available/dietpi-nextcloud.ini ln -s /etc/php/7.4/mods-available/dietpi.ini /etc/php/8.2/mods-available/dietpi.ini
- Enable the DietPi configuration for PHP 8.2
phpenmod dietpi phpenmod dietpi-nextcloud
service php8.2-fpm restart
Now you need to edit the configuration for nginx to instruct it to use PHP 8.2.
- Open the configuration file with nano to edit it
You can use
CTRL
+w
to search in the file, withCRTL
+o
you can save the changed file and withCRTL
+x
you can close the editor.nano /etc/nginx/nginx.conf
- Find the following section:
Change the "server" from "unix:/run/php/php8.1-fpm.sock;" to "unix:/run/php/php8.2-fpm.sock;". (If you followed the PHP 8.0 upgrade guide, the line will read "unix:/run/php/php8.0-fpm.sock;" instead of 8.1.) The section should now read like this:
upstream php { server unix:/run/php/php8.1-fpm.sock; }
upstream php { server unix:/run/php/php8.2-fpm.sock; }
- Now save the file with
CRTL
+o
and exit the editor withCRTL
+x
- Restart nginx
service nginx restart
By default, your DietPi should now be using PHP 8.2.
You can check this by running php -v
. The output should look like this:
root@DietPi:~# php -v
PHP 8.2.12 (cli) (built: Oct 27 2023 13:01:32) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
with Zend OPcache v8.2.12, Copyright (c), by Zend Technologies
It's important that it shows PHP 8.2.*
.
If it doesn't, use the command update-alternatives --config php
to set PHP 8.2 as default.
Select the option with the path "/usr/bin/php8.2" and confirm.
root@DietPi:~# update-alternatives --config php
There are 2 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/php8.2 82 auto mode
1 /usr/bin/php7.4 74 manual mode
2 /usr/bin/php8.1 81 manual mode
3 /usr/bin/php8.2 82 manual mode
Press <enter> to keep the current choice[*], or type selection number:0
Check for server and app updates for your Nextcloud.
- Check for updates
ncc update:check
- Install the passwords app if not installed
ncc app:install passwords
- Install updates of the passwords app if available
ncc app:update passwords
Log into your Nextcloud with an admin account. Go into "Administration Settings" and scroll all the way down in the left sidebar to "System". Open the System section and scroll down to "PHP". It should confirm you're using PHP 8.2.
Congratulations! You're done with the upgrade to PHP 8.2 now. To verify that everything has worked, log into your Nextcloud, click on your account icon and click on "Administration settings". There, open the "System" section and scroll down to PHP. You should also go to the "Overview" section and take care of any warnings that show up there.
- It can take a day before app updates show up in the apps store
You can switch back to PHP 8.1 at any time if something does not work.
- First, edit the configuration for nginx and instruct it to use PHP 8.1 again.
You can use
CTRL
+w
to search in the file, withCRTL
+o
you can save the changed file and withCRTL
+x
you can close the editor.nano /etc/nginx/nginx.conf
- Find the section that you changed:
Change the "server" from "unix:/run/php/php8.2-fpm.sock;" back to "unix:/run/php/php8.1-fpm.sock;". The section should now read like this:
upstream php { server unix:/run/php/php8.2-fpm.sock; }
upstream php { server unix:/run/php/php8.1-fpm.sock; }
- Now save the file with
CRTL
+o
and exit the editor withCRTL
+x
- Restart nginx
service nginx restart
- Now run the command
update-alternatives --config php
to select which PHP version should be used for the command line. Select the option with the path "/usr/bin/php8.1" and confirm.root@DietPi:~# update-alternatives --config php There are 2 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/php8.2 82 auto mode 1 /usr/bin/php7.4 74 manual mode 2 /usr/bin/php8.1 81 manual mode 3 /usr/bin/php8.2 82 manual mode Press <enter> to keep the current choice[*], or type selection number: 2