phpcentos8

Is there a way to change default php version in yum module list php in Centos 8


When I run sudo yum module list php, get next list:

CentOS Stream 8 - AppStream Name Stream Profiles
php 7.2 [d] common [d], devel, minimal
php 7.3 common [d], devel, minimal
php 7.4 [e] common [d] [i], devel, minim php 8.0 common [d], devel, minimal
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

As you can see php 7.2 is set as default[d] but php 7.4 is enabled[e].

It causes confusion because sometimes I need to be sure which php version will be use.

There is a way to set 7.4 as default as well?


Solution

  • This example is for the Remi Repo, however the command is the same for others but the module might be under a different header/name. You can likely figure it out for your existing repo by looking at the list of available PHP modules on your CentOS installation using this command:

    dnf module list php
    

    It is best to update to the latest stable PHP version which at the moment is version 8.1.

    Assuming you have it installed with all the desired modules, on CentOS Stream 8 the command to enable the Remi Repo PHP version 7.4 is:

    dnf module switch-to php:remi-7.4
    

    .. based on what you posted above, the command might be:

    dnf module switch-to php:7.4
    

    To determine which PHP version is being used by default, use this command:

    php -v
    

    If you set your webserver to use PHP-FPM, it will use the default version automatically.