Enabling PHP 8.0

Enabling PHP 8.0

by Adrian Sobers -
Number of replies: 17
Hi,

We are in the process of preparing to upgrade to Moodle 4.2 and the server check is flagging the PHP version as needing attention:



However, when I check from the command line the PHP version says otherwise:


Do I have to "enable" the higher version of PHP so the upgrade checker in Moodle can detect the correct version? Thanks for any help/guidance on how to proceed here.

Regards,
Adrian
Average of ratings: -
In reply to Adrian Sobers

Re: Enabling PHP 8.0

by Ken Task -
Picture of Particularly helpful Moodlers
php-cli is not the same php executable run by web service.

Please see:

as well as release notes for 4.2.

Also, you are upgrading to 4.2 from what version?

Uhhh - 4.1 is long term support.

'SoS', Ken


In reply to Ken Task

Re: Enabling PHP 8.0

by Adrian Sobers -
Hi Ken,

I'm aware that 4.1 is LTS but 4.2 was requested for this particular environment. I'm upgrading from 4.1.

I'll check the links and post and further queries. Thanks for your reply.

Regards,
Adrian
In reply to Adrian Sobers

Re: Enabling PHP 8.0

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Just to reiterate... asking for the version on the command line doesn't help you. While command line PHP *might* be the same version as running in the web, it doesn't have to be. They are completely separate software installs.
Average of ratings: Useful (1)
In reply to Howard Miller

Re: Enabling PHP 8.0

by Adrian Sobers -
Thanks Howard.

I figured out how to enable/disable the different php versions. However after enabling php8.0 (then restarting apache), I get this error when loading the page to re-run the server check, "PHP has not been properly configured with the MySQLi extension for it to communicate with MySQL."

If I set it back to php7.4 and restart apache the page loads fine.

Regards,
Adrian
In reply to Adrian Sobers

Re: Enabling PHP 8.0

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
It's because you're missing the 'mysqli' PHP extension for PHP8.0. How you fix that depends on how PHP 8 was installed in the first place. Most Linux OSs have package managers that take care of that sort of thing.

For example, UBuntu would be something like...

sudo apt install php8.0-mysqli
In reply to Howard Miller

Re: Enabling PHP 8.0

by Adrian Sobers -
I came across that and attempted to use the same command but got this for 8.0:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package php8.0-mysqli
E: Couldn't find any package by glob 'php8.0-mysqli'


But 8.1 returns:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'php8.1-mysql' instead of 'php8.1-mysqli'
php8.1-mysql is already the newest version (8.1.2-1ubuntu2.11).
The following packages were automatically installed and are no longer required:
accountsservice alsa-topology-conf alsa-ucm-conf at bsdmainutils cryptsetup-run dconf-gsettings-backend
dconf-service dnsutils g++-9 glib-networking glib-networking-common glib-networking-services
gsettings-desktop-schemas language-selector-common libaccountsservice0 libapache2-mod-php7.2 libasound2
libasound2-data libboost-iostreams1.71.0 libcanberra0 libcbor0.6 libclass-accessor-perl libcroco3 libdconf1
libdns-export1109 libevent-2.1-7 libffi7 libfl2 libfuse2 libhogweed5 libicu66 libidn11 libio-string-perl
libjs-openlayers libjson-c4 liblua5.2-0 libmpdec2 libnettle7 libntfs-3g883 libogg0
libparse-debianchangelog-perl libperl5.30 libproxy1v5 libpython3.8 libpython3.8-minimal libpython3.8-stdlib
libreadline5 libsensors4-dev libsnmp35 libsoup2.4-1 libsoup2.4-common libstdc++-9-dev libtdb1 liburcu6
libvorbis0a libvorbisfile3 ltrace lz4 ncal perl-modules-5.30 php-twig-extensions php7.2 php8.0
popularity-contest python3-entrypoints python3-requests-unixsocket python3-simplejson python3.8
python3.8-minimal session-migration sound-theme-freedesktop
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

When I attempt to load the server check page on the site I get a bunch of PHP errors:

Duplicate admin category name: users
line 985 of /lib/adminlib.php: call to debugging()
line 31 of /admin/settings/top.php: call to admin_category->add()
line 8818 of /lib/adminlib.php: call to require()
line 4501 of /lib/navigationlib.php: call to admin_get_root()
line 4364 of /lib/navigationlib.php: call to settings_navigation->load_administration_settings()
line 833 of /lib/pagelib.php: call to settings_navigation->initialise()
line 962 of /lib/pagelib.php: call to moodle_page->magic_get_settingsnav()
line 761 of /lib/classes/navigation/views/secondary.php: call to moodle_page->__get()
line 236 of /lib/classes/navigation/views/secondary.php: call to core\navigation\views\secondary->load_admin_navigation()
line 890 of /lib/pagelib.php: call to core\navigation\views\secondary->initialise()
line 962 of /lib/pagelib.php: call to moodle_page->magic_get_secondarynav()
line 70 of /theme/boost/layout/drawers.php: call to moodle_page->__get()
line 1477 of /lib/outputrenderers.php: call to include()
line 1403 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
line 2967 of /lib/outputrenderers.php: call to core_renderer->header()
line 1973 of /lib/setuplib.php: call to core_renderer->fatal_error()
line 390 of /lib/setuplib.php: call to bootstrap_renderer->__call()
line ? of unknownfile: call to default_exception_handler()
In reply to Adrian Sobers

Re: Enabling PHP 8.0

by Ken Task -
Picture of Particularly helpful Moodlers
Truth in sharng .. not running Ubuntu, but can google!

Package managers ... gotta love 'em! sad [NOT!]

php8.0-mysqli
php8.0-mysql
are not the same ... see the 'i' at the end of the first?

sudo apt-get install php8.0-mysqlnd
nd stands for 'native driver' in case you were wondering! smile

Your 8.1 said ...
The following packages were automatically installed and are no longer required:

Then it list them.
I don't recognize any of them as required for Moodle.

Also provides a command to remove them:
sudo apt autoremove

Resource:
https://www.digitalocean.com/community/tutorials/how-to-install-php-8-1-and-set-up-a-local-development-environment-on-ubuntu-22-04

sudo apt install --no-install-recommends php8.1

The --no-install-recommends flag will ensure that other packages like the Apache web server are not installed.

'SoS', Ken

In reply to Adrian Sobers

Re: Enabling PHP 8.0

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

Do you get many of the Duplicate admin category name errors? They could be hiding the cause. An error on this page can cause lots of unrelated error messages (see MDL-69873).

If you attach all the errors as a text file maybe we can spot the cause. Or maybe you can spot one error that's different to the others.

In reply to Leon Stringer

Re: Enabling PHP 8.0

by Adrian Sobers -
Attaching duplicate error listing.
In reply to Adrian Sobers

Re: Enabling PHP 8.0

by Adrian Sobers -
Hi Ken,

Your link worked, many thanks. I'm now getting this when I run my server checks:





I'll work on these now and update the thread if any more issues. Thanks for your help so far guys.


Regards,

Adrian


In reply to Adrian Sobers

Re: Enabling PHP 8.0

by Adrian Sobers -
I'm down to the last one now: php_extension intl
In reply to Adrian Sobers

Re: Enabling PHP 8.0

by Adrian Sobers -
Upgrade to 4.2 completed. Thanks Leon, Ken, and Howard.
In reply to Adrian Sobers

Re: Enabling PHP 8.0

by Ken Task -
Picture of Particularly helpful Moodlers
Congrats!    And thanks for the thanks, but wondering if you wouldn't mind providing a summary of what you did to resolve the issues - especially the setup of PHP 8.0 - for others who might host where you host and face the same issues. smile

'SoS', Ken

In reply to Ken Task

Re: Enabling PHP 8.0

by Adrian Sobers -
Hi Ken,

I followed the instructions on the link you sent to setup the compatible version of PHP to meet the requirement for 4.2: 

https://www.digitalocean.com/community/tutorials/how-to-install-php-8-1-and-set-up-a-local-development-environment-on-ubuntu-22-04


After that was done satisfying the other two warnings were straightforward. I had to remove the assignments mod folder and install another extension that I found by searching.

The installation of 4.2 went smoothly after that. Let me know if you need anymore details.


Regards,

Adrian


In reply to Adrian Sobers

Re: Enabling PHP 8.0

by Ken Task -
Picture of Particularly helpful Moodlers
Thanks for explaining further ...
This part:
"had to remove the assignments mod folder"

Assignments had a major change many versions ago ... the old assignments mod showed as (assignments 2.2) and hidden by default (if I recall correctly).  

New assignments now under a directory named 'assign'.  Way back when, there was a site admin menu item that would show if site hadn't made the conversion to new yet (assignment upgrade helper).

That assignment directory is still present in 4.0 and 4.1 but not in 4.2.

So moodle core finally decided to remove it.

Anyhoo ... just additional infomation to support your action! smile
Thanks for posting back!

'SoS', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: Enabling PHP 8.0

by Adrian Sobers -
Thanks for that information Ken. I've forwarded it to our internal Moodle resource. I was able to upgrade the other sites so we're good to go now. Thanks again.
In reply to Adrian Sobers

Re: Enabling PHP 8.0

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

This output ends with:

Exception - Call to undefined function mb_list_encodings()
Exception - Call to undefined function mb_list_encodings()

Have you got the PHP extension php-mbstring installed? On my system this is in package php-mbstring-8.0.26.