Upgrade php 7.4 to 8.0 on Ubuntu

Hi.
Maybe you can help me.
I am trying to upgrade PHP 7.4 to 8.0. Everything seems to install, but the system is running on the old configuration 7.4. I am newby on linux and nextcloud and just learning and donā€™t know what to do.

Hi,
You need to enable the new php version and disable the old:

sudo a2enmod php8.0
sudo a2dismod php7.4

Did it, didnā€™t help.
Maybe I did something wrong, or just didnā€™t finish what I should have done? I could not find a complete tutorial on how to update PHP.

Could you post the output of this three commands:

dpkg -l | awk '/^ii.*php/ {print $2}'
apachectl -tD DUMP_INCLUDES | sed -n '/php.*conf/ s#.*/\([^/]*\)\.conf#\1#p'
update-alternatives --get-selections | grep -E "ph(ar|p)"

have you restart your apache after enabilng the new php version?

this is what I mainly did:
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.0 libapache2-mod-php8.0
sudo systemctl restart apache2
sudo apt update
sudo apt install php8.0-fpm libapache2-mod-fcgid
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.0-fpm
a2disconf php7.4-fpm
systemctl restart apache2

root@nextcloud:~# dpkg -l | awk ā€˜/^ii.php/ {print $2}ā€™
libapache2-mod-php8.0
php-cli
php-common
php-pear
php7.4-bcmath
php7.4-bz2
php7.4-common
php7.4-curl
php7.4-dev
php7.4-gd
php7.4-gmp
php7.4-imap
php7.4-intl
php7.4-json
php7.4-ldap
php7.4-mbstring
php7.4-opcache
php7.4-pgsql
php7.4-readline
php7.4-soap
php7.4-xml
php7.4-zip
php8.0
php8.0-cli
php8.0-common
php8.0-fpm
php8.0-opcache
php8.0-readline
php8.2-common
php8.2-opcache
php8.2-readline
pkg-php-tools
root@nextcloud:~# apachectl -tD DUMP_INCLUDES | sed -n '/php.conf/ s#./([^/]
).conf#\1#pā€™
php8.0
php8.0-fpm
root@nextcloud:~# update-alternatives --get-selections | grep -E ā€œph(ar|p)ā€
phar auto /usr/bin/phar.default
phar.phar auto /usr/bin/phar.phar.default
php auto /usr/bin/php.default
php-config auto /usr/bin/php-config7.4
php-fpm.sock auto /run/php/php8.0-fpm.sock
phpize auto /usr/bin/phpize7.4

Some packages are missing. To install all packages you had with 7.4, run this command:

sudo apt install php8.0-{$(dpkg -l | awk -F "  |-" '/^ii.*php7.4/ {printf "%s,", $3} END {printf "\n"}' | sed 's/,$//')}

Then, you can only use libapache2-mod-php OR php-fpm. Both is not possible, and how it looks, you did it with libapache2-mod-php before. So you should deinstall the php8.0-fpm.

Then switch all php related alternatives manualy to 8.0. Youā€™ll see them one by one with this command, and then choose 8.0 each time:

for linkgroup in `ls /var/lib/dpkg/alternatives/ | grep -E "ph(ar|p)"`; do sudo update-alternatives --config $linkgroup; done

Then restart your webserver and look if it works. If not, donā€™t hesitate to ask for more help

2 Likes

Maybe you can tell me how to do it right from the beginning? I have a snapshot and I can return everything to the way it was before.
I donā€™t want to fix the mistakes, but just do it right from the beginning.

but that is the way you learn most. After fixing those mistakes, you are free to repeat the update as much times as you want with your snapshot, untill you understood it.

Iā€™m not responsible for your whims, whether you want to fix ā€˜mistakesā€™ or repeat everything until itā€™s right, as the result is exactly the same, Iā€™m mostly interested in whether my steps solved the problem or not?

1 Like

You can do the update with the php-updater script like I described here in this post

Therefore you should roll back with your snapshot to your previous state

I agree with you, mistakes always develop knowledge. But it is useful when you understand more than nothing in what you do :). So at this point of my level of knowledge, Iā€™m looking for a way to get it right, and learn in the process. I do roll back several times, the result is not better, so I want to do once right, as more updates are still to come.
Thanks for the tip, I will try to do it :slight_smile:

1 Like

OK, this is a usefull knowledge:

The automatic update from one to the next php-version is done by so called ā€œdependency-packagesā€ like ā€˜php ā€™ and other packages with names like php-{module} (without the version String) Those packages allways depend on the latest version (which is 8.2 at the moment) and can almost all safely be removed, what will give you back the control over your php-version. When you try to deinstall such a package, you will see if it is a dependency for one or more php8.1-* modules (like php-common which is allways needed). All other packages that donā€™t meet any dependencies can and should be removed.
A package as ā€˜php8.1 ā€™ is a so caled ā€œmeta-packageā€ and can be removed as well.

Then you should only install the packages WITH version string (php8.1-{module} instead of php-{module}).

Then you should do the update-alternatives as I described in #18 of this thread.

1 Like

The script did not work properly. It crashed with an error. What can I do about it and where should I look?

Reading state informationā€¦ Done
The php8.1-json package is a virtual package provided by:
php8.1-phpdbg 8.1.18-1+ubuntu20.04.1+deb.sury.org+1
php8.1-fpm 8.1.18-1+ubuntu20.04.1+deb.sury.org+1
php8.1-cli 8.1.18-1+ubuntu20.04.1+deb.sury.org+1
php8.1-cgi 8.1.18-1+ubuntu20.04.1+deb.sury.org+1
libphp8.1-embed 8.1.18-1+ubuntu20.04.1+deb.sury.org+1
libapache2-mod-php8.1 8.1.18-1+ubuntu20.04.1+deb.sury.org+1
You have to explicitly select one of them to install.

E: The ā€˜php8.1-jsonā€™ package is not a candidate for installation

The return code for the last step is 100
something went wrong, exit

Thank you verry much for your feedback, it helps me to improve the script.

I changed the script, so that it does not stop because of this message (which is in fact not an error message but an information).

Please execute the following command to get back to the original state before calling the script:

apt-get remove --purge *php8.1*

Run the script again, it will offer an update. Now it should work.

Hi.
Thank you for edituing script, now it worked, there was also a message, but the work did not stop.
I think I did everything as described in the post with the script. But there you also stopped and did not suggest further steps for nextcloud to know which php it should work with now :slight_smile: .

OK. So now you updated your php. Fine.

You need to know now, how your php comunicates with your apache2.

There are two posibilties:

  • libapache2-mod-php
  • php-fpm

The latter is the ā€œfast process managerā€ and has http2 support (my recommendation).
But what you used before the update also plays a role for you.

This way you can find out, which sapi versions are installed on your system:

for version in 7.4 8.1; do echo "sapi of version $version: $(echo "$(find /etc/php/$version -name "php.ini" -type f 2>/dev/null)" | cut -d'/' -f5 | sort -u | grep -vE 'cli|phpdbg')"; done

You should now see either apache2 or fpm. Donā€™t try to activate a sapi that is not shown here!

Steps to activate php-fpm:

(first line is to disable an eventualy apache2-mod-php first)

sudo a2dismod php7.4 php8.1 mpm_prefork
sudo a2enmod mpm_event proxy_fcgi setenvif
sudo a2disconf php7.4-fpm
sudo a2enconf php8.1-fpm

(restart your webserver)

and if you do NOT want to use php-fpm but libapache2-mod-php instead:

Steps to activate libapache2-mod-php:

The latest apache2-module already should be activated, as far as it is installed or if not deactivated by the former step.
These steps can be taken to ensure it is activated.
(first 2 lines are to disable an eventaly installed php-fpm):

sudo a2disconf php7.4-fpm php8.1-fpm
sudo a2dismod mpm-event
sudo a2dismod php7.4
sudo a2enmod mpm_prefork php8.1

(restart your webserver)

Many of these steps will echo that it is already set. It doesnā€™t matter, you canā€™t set anything twice, so it is safe.


So read carefully, you should only activate one of both.


As a final step, you can (should) switch all php alternatives to manual mode to 8.1 to prevent unattended upgrades to another version without your knowledge.

Therefor call this command which switches all alternatives from auto to manual to the 8.1 version:

sudo update-alternatives --get-selections | grep -E "ph(ar|p)" | sed 's/auto/manual/;s/[78].[124]/8.1/' | sudo update-alternatives --set-selections

Now you should control it step by step with this command and adjust - if you want it later - this way:

for linkgroup in `ls /var/lib/dpkg/alternatives/ | grep -E "ph(ar|p)"`; do sudo update-alternatives --config $linkgroup; done

Much luck

Thanks for the tips.
But I must be doing something wrong anyway, because nextcloud thinks I have php 7.4.3 running.
image

As far as I understand I am using php-fpm:
root@nextcloud:/etc/php# for version in 7.4 8.1; do echo ā€œsapi of version $version: $(echo ā€œ$(find /etc/php/$version -name ā€œphp.iniā€ -type f 2>/dev/null)ā€ | cut -dā€™/ā€™ -f5 | sort -u | grep -vE ā€˜cli|phpdbgā€™)ā€; done
sapi of version 7.4: fpm
sapi of version 8.1: fpm

All alternatives are in manual mode, nothing automatic.

and after the upgrade, something went wrong with cron.php :frowning: Iā€™m not so good to figure out whatā€™s wrong and why the background job isnā€™t running :frowning:
:frowning: whatā€™s wrong with my nextcloud or meā€¦

Did you follow the steps to activate php-fpm from my previous answer?
(including restarting the webserver):

sudo systemctl stop php7.4-fpm
sudo systemctl restart apache2 php8.1-fpm

Do you even have a server install or some docker/snap/image/aio/?

Yes, what was in the previous post I did. I didnā€™t see those two commands, I did them now, and the server went down. There was a message saying that Servise unavailable. After I completely rebooted the server, the site is up but it still gives out that php 7.4.3 is in use.
As far about what is installed, this is a VM downloaded through a nextcloud.com with a link to a third party company. Just because I have extremely little experience in deploying such systems from the begining I took a virtual machine. At that moment, I thought it was a good idea. Now I realize that I should have done more research and tried to do things differently. :frowning: