How do I change the default PHP base-version on shell?

馋奶兔 提交于 2021-02-02 09:09:43

问题


I have Centos 7 and Virtualmin installed, with the tipycal php-fpm 5.4, 7.0, 7.1 that you can choice between the versions you prefer on every virtualhost via Virtualmin control panel, and everything works well.

But when I access to the server via SSH and check php -v I get this:

PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

How can I select another php default/base version for the shell system?


回答1:


When you issue the php command on the shell it uses the default php version on the server which in your case is php-5.4.16

To use another php version, you have to check where the binaries for those php versions are and invoke them with their full path rather than just typing php.

For example, on CentOS, for PHP 7.2 for example, the full path of the php binary is: /opt/rh/rh-php72/root/usr/bin/php

root@virtualmin /root
» /opt/rh/rh-php72/root/usr/bin/php -v
PHP 7.2.24 (cli) (built: Nov  4 2019 10:23:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend Technologies



回答2:



Install versions of PHP in centos 7


Setup Yum Repository First of all, you need to enable Remi and EPEL yum repositories on your system. Use the following command to install EPEL repository on your CentOS and Red Hat 7/6 systems

Use this command to install EPEL yum repository on your system

 sudo yum install epel-release

and now execute one of the following commands as per your operating system version to install the Remi repository.

sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

Install PHP 7 on CentOS Your system is prepared for the PHP installation from yum repositories. Use one of the following commands to install PHP 7.4 or PHP 7.3 or PHP 7.2 or PHP 7.1 on your system based on your requirements.

Install PHP 7.4

yum --enablerepo=remi-php74 install php

Install PHP 7.3

yum --enablerepo=remi-php73 install php

Install PHP 7.2

yum --enablerepo=remi-php72 install php

. Check version PHP install

php -v

.

PHP 7.4.1 (cli) (built: Dec 17 2019 16:35:58) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Install PHP Modules You may also need to install additional PHP modules based on your application requirements. The below command will install some more useful PHP modules.

For PHP 7.4

yum --enablerepo=remi-php74 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

For PHP 7.3

yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

For PHP 7.2

yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt


来源:https://stackoverflow.com/questions/56198160/how-do-i-change-the-default-php-base-version-on-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!