Score:0

Can't get Apache2 to use PHP8.1 on Ubuntu server 20.04

cg flag

I have an Ubuntu server 20.04 installation that among other things is running a bare-metal Nextcloud instance using Apache as the web server. I have multiple PHP versions installed, but up to this point Apache was using PHP 7.4. Since Nextcloud deprecated it, I was trying to migrate to PHP 8.1 (the new recommended version, still no support for PHP 8.2). I tried following many guides on how to do this, all of them basically boil down to installing PHP 8.1 and the needed modules, use a2dismod php7.4 to disable the old PHP version, enable the new one with a2enmod php8.1 and restart Apache with systemctl restart apache2. This is the last one I followed: link. But despite this, Apache keeps using PHP 7.4. If I try to uninstall PHP 7.4, my Nextcloud installation just breaks (I get a 503 error). I tried with slight variations, but always failed and ended up restoring the lvm snapshot I created before the attempt. But I still didn't restore the snapshot of the last attempt, here I did all the steps in the linked guide and I didn't uninstall PHP 7.4, so my Nextcloud is still working but using the wrong version. What can I check or try to fix this? Thank you for your help,

GTP

in flag
Did you remember to use `update-alternatives` to set the default PHP version?
GTP95 avatar
cg flag
I didn't, but when I try to run `php -v` I either get PHP 8.1.something or PHP 8.2.something (depending on whether I also uninstall the PHP versions I don't need or not, the default is PHP 8.2.something). In no case do I get PHP 7.4. Does it still matter?
GTP95 avatar
cg flag
I just tried, but unfortunately it didn't work. After running `update-alternatives --config php` and selecting PHP 8.1 (before the default was PHP 8.2), if I do `php -v` from the terminal I get PHP 8.1.14, but Nextcloud is still running with PHP 7.4.33. Any idea?
Score:0
cg flag

In the end, the problem turned out to be that I had two different websites (not Nextcloud itself) that in their .conf file inside the sites-enabled directory specifued PHP7.4-fpm as their handler as follows: SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/" Disabling those fixed the problem. So it seems that Apache2 gets confused if one website specifies a version of PHP-fpm and the others don't, and ends up forcing that version to all websites. I'm leaving those disabled for now as I'm not using them, but I'll put a note somewhere to remember me to update their config or Nextcloud's config in case I wish to use them again.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.