To switch php version of Ubuntu server
Sometimes we need to change or switch different version of php in Linux/Ubuntu Server for checking php version compatibility. This snippet is very essential to switch among php versions.
To check current version of php: php -v
To Install Other version of php:
First add repository of php maintainer
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get upgrade
execute following command to install any of the version.
sudo apt-get install php7.1 # for PHP 7.1
sudo apt-get install php7.0 # for PHP 7.0
sudo apt-get install php5.6 # for PHP 5.6
After installation of other versions of php you may need to switch among php versions.
To switch between installed versions use: sudo update-alternatives –config php
Then you must set Apache to work with right version:
sudo a2dismod php7.1 # unload the current version
sudo a2enmod php5.6 # load the version you need
Finally Restart Apache2 Server: sudo service apache2 restart # restart webserver to apply
Comments
Comments for this post are closed.