skip to Main Content

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?

2

Answers


  1. 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.

    Login or Signup to reply.
  2. #1 Answer by @ChenZen does not give a solution to the OP’s Question
    The Question:
    Is there a way to change default php version?

    #1 Answer by Chen Zen explains how to Enable another version of PHP and while it is useful information and probably should be attached following the answer to the OP’s question, it does not answer the OP’s Question.

    You unfortunately can not change the default [d] php of a repo as this is defined by the repo and you do not have control over this.

    Your best bet as outlined in #1 answer of Chen Zen is to Enable [e] your prefered version which will allow you to use the php version that you enable.

    However, don’t get it twisted, enabling your desired php version and setting the default version of the repo are NOT the same. They are two entirely different things. In most cases just enabling the php version that you want/need to use should be an adequate solution.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search