Add PPA, trusted by many developers:
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
Install php 7.1
sudo apt-get install php7.1
Search and install specific PHP 7.1 modules
sudo apt-cache search php7.1
Install most commonly used modules
sudo apt-get install php7.1 php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm