16

I have two versions of PHP in opt/remi folder php56 and php72 but when I php -v on cmd it shows:

Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans

How to set default version to PHP 7.2?

simhumileco
  • 31,877
  • 16
  • 137
  • 115
ata
  • 1,254
  • 1
  • 9
  • 30

4 Answers4

37

I have two versions of PHP in opt/remi folder php56 and php72

how to set default version to PHP 7.2

SCL are designed for parallel installation so don't alter default version in base system

Once the collection is enabled, the version will be used

$ scl enable php72 bash
$ php -v
PHP 7.2.8 (cli) (built: Jul 17 2018 05:35:43) ( NTS )

If you want 7.2 to be the default version (base system) you should install it, according to Wizard instructions for "Default / single version" (and keep 5.6 as secondary version)

Community
  • 1
  • 1
Remi Collet
  • 6,198
  • 1
  • 20
  • 25
5

Change php cli version in Centos 7

First, find your php7, run phpinfo() and get path or you can do with other ways. for me, it is:

/usr/local/lsws/lsphp73/

then:

cd ~
. ~/.bash_profile

And:

alias php='/usr/local/lsws/lsphp73/bin/php'

Now:

php -v

PHP 7.3.13 (cli) (built: Dec 20 2019 16:02:35) ( NTS )

Pedram
  • 15,766
  • 10
  • 44
  • 73
1

Create a file "/etc/profile.d/php.sh". Use pathmunge to add the path to your php bin you want as default on line one and save the file.

Example:

pathmunge /opt/remi/php73/root/bin

Reload your profile afterwards by logging in again.

Now if you do a which php and php -v you should see the following output in my case

[root@host etc]# which php
/opt/remi/php73/root/bin/php
[root@host etc]# php -v
PHP 7.3.4 (cli) (built: Apr  2 2019 13:48:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies
   with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com  (unconfigured) v10.3.4, Copyright (c) 2002-2019, by ionCube Ltd.

This is the preferred way to accomplish this task using tools that are already supplied on a minimal install. This also allows scripts and commands to hit the correct php binaries when accomplishing other tasks. Commands like, pear, pecl, phar, php-config. You want your experience to be global when setting the default, otherwise you might wind up still getting version 5.6's tools when trying to install an extension or complete another task.

  • While PATH is enough for PHP, it is not for other SCLs, ". scl_source enable xxx" is better (or "module load xxx" when available). These commands also redirect LD_LIBRARY_PATH, man pages, ...) – Remi Collet Apr 30 '19 at 07:06
  • And again, if you want a single version, don't use SCL designed for multiple versions, see the wizard: https://rpms.remirepo.net/wizard/ – Remi Collet Apr 30 '19 at 07:16
1
module enable php74

for your understanding:

cat /opt/remi/php74/enable
export PATH=/opt/remi/php74/root/usr/bin:/opt/remi/php74/root/usr/sbin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/remi/php74/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/remi/php74/root/usr/share/man:${MANPATH}
user7568519
  • 113
  • 5
  • 1
    "scl" command uses the /opt/remi/php74/enable file, while the "module" command use the /usr/share/Modules/modulefiles/php74 file, but goal is the same. – Remi Collet Oct 23 '20 at 09:03
  • and what is the difference between module php74 and Software Collection php74? – user7568519 Oct 23 '20 at 11:12
  • 1
    There is no difference, "scl" command or "module" command are only different way to enable the software collection. Both are available for package from my repository – Remi Collet Oct 23 '20 at 12:27