Switching Between PHP Versions

If you have installed more than one PHP version and want to use one other than the default, let's look at how to switch between them. As an example, I will show it between PHP 5.6 and PHP 7.1.
First, let's find out which PHP version is our default.
If you like, you can upload a php info file to the site and find out that way.
phpinfo(); // Gives all the details about PHP. phpversion() ; // Returns only the PHP version.
Or let's enter the command below on our server;
$ php -v
$ php --version
// The output of these commands looks like this;
PHP 7.1.0-5+deb.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.1.0-5+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies
To switch between PHP 5.6 and PHP 7.1, let's follow the steps below.
PHP 7.1 => PHP 5.6 (switching from PHP 7.1 to PHP 5.6)
Apache:- $ sudo a2dismod php7.1 $ sudo a2enmod php5.6 $ sudo service apache2 restart CLI:- $ sudo update-alternatives --set php /usr/bin/php5.6
PHP 5.6 => PHP 7.1 (switching from PHP 5.6 to PHP 7.1)
Apache:- $ sudo a2dismod php5.6 $ sudo a2enmod php7.1 $ sudo service apache2 restart CLI:- $ update-alternatives --set php /usr/bin/php7.1
Finally, you can check the version again to see that it has changed. You can use the same command for other PHP versions.
*Ubuntu 16.10, 16.04 LTS, 14.04 LTS or 12.04 LTS
Take care...
PHP,Version,Sürüm,Geçiş,Ubuntu,Sunucu,Apache,phpinfo(),phpversion()