## Install PHP version on ubuntu
### show installed php
```
$sudo apt show php
OR
$ sudo apt show php -a
```
### install repos for php versions
```
$ sudo apt install python-software-properties
$ sudo add-apt-repository ppa:ondrej/php
```
### update system
```
$ sudo apt-get update
```
### Set Default PHP Version in Ubuntu
```
------------ Set Default PHP Version 7.1 ------------
$ sudo update-alternatives --set php /usr/bin/php7.1
```
### To set the PHP version that will work with Apache web server, use the commands below.
First disable the current version with the a2dismod command and then enable the one you want with the a2enmod command.
```
$ sudo a2dismod php7.0
$ sudo a2enmod php7.1
$ sudo systemctl restart apache2
```
### After switching from one version to another, you can find your PHP configuration file, by running the command below.
```
------------ For PHP 5.6 ------------
$ sudo update-alternatives --set php /usr/bin/php5.6
$ php -i | grep "Loaded Configuration File"
------------ For PHP 7.0 ------------
$ sudo update-alternatives --set php /usr/bin/php7.0
$ php -i | grep "Loaded Configuration File"
------------ For PHP 7,1 ------------
$ sudo update-alternatives --set php /usr/bin/php7.1
$ php -i | grep "Loaded Configuration File"
```
### Restart apache
```
sudo service apache2 restart
```