Score:0

php -v and phpinfo(); returns different versions

fr flag

I want to use php 8.1 on Ubuntu server Currently it works with php 7.4.30

lsb_release -a

returns

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.6 LTS
Release:    18.04
Codename:   bionic

I followed tutorials and so I executed these commands

sudo apt update
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.1
sudo apt-get install -y php8.1-cli php8.1-common php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath
sudo systemctl restart apache2

Now when I do php -v I see:

PHP 8.1.18 (cli) (built: Apr 14 2023 04:39:07) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.18, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.18, Copyright (c), by Zend Technologies

when I do

sudo update-alternatives --config php

 Selection    Path             Priority   Status
---------------------------------------------
* 0            /usr/bin/php8.1   81        auto mode
  1            /usr/bin/php7.3   73        manual mode
  2            /usr/bin/php7.4   74        manual mode
  3            /usr/bin/php8.1   81        manual mode

Same for sudo update-alternatives --config phar and sudo update-alternatives --config phar.phar , php 8.1 is selected.

However, my application (a CMS) is still in php 7.4 I also tested with a simple php file with phpinfo();

What else can I check?

guiverc avatar
cn flag
Ubuntu 18.04 LTS was released in 2018-April with 5 years of *standard* supported life; you can use `ubuntu-support-status` to confirm the life remaining... It was extended by 1 month by Canonical for some architectures, but I'd suggest planning for your *release-upgrade* asap.
Sébastien Gicquel avatar
fr flag
@guiverc Thank you for the info. I did not know. I'm a web developer and not a server expert. Is it possible that my php version problem comes from my Ubuntu obsolete version?
in flag
I'm not seeing any `sudo a2enmod php8.1` in there ...
Sébastien Gicquel avatar
fr flag
@matigo I thought select php version with `sudo update-alternatives --config php` could be used instead of `a2enmod php8.1`, this is not the case?
in flag
PHP CLI != Apache PHP
cn flag
what matigo said: the 2 are not the same :) "However, my application (a CMS) is still in php 7.4 I also tested with a simple php file with phpinfo();" you need a newer apache ;)
Sébastien Gicquel avatar
fr flag
Thank you for your help, the solution was indeed `sudo a2dismod php7.4` + `sudo a2enmod php8.1` If someone want to post the solution, I will accept it.
Score:0
my flag

Probably you'll need to check php.ini.

In phpinfo() page, you will see which php.ini your web server is using. If you're seeing 7.4, probably your php.ini path would be something like:

.../7.4/apache2/php.ini

Just find the php.ini file for your php v8.1 installation and change the settings in your web server so it points to it.

Score:0
fr flag

PHP CLI is not the same as the PHP Apache module.

See this answer for more informations

So the solution is to tell Apache to use the installed version of PHP 8.1 by disabling the old PHP module and enabling the new PHP module using the following command.

sudo a2dismod php7.4
sudo a2enmod php8.1
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.