To install php7.1 you don't need to delete php5. PHP 7.1 will be installed in a separate folder /etc/php/7.1/
First add Dotdeb PPA and import the GPG key of Dotdeb repository

apt-get install apt-transport-https lsb-release ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg

Then add PPA in your server and update

echo 'deb jessie main' > /etc/apt/sources.list.d/php.list
apt-get update

Let's see what php7.1 packages there are for installation

apt-cache search php7.1

Select the packages you need and install

apt-get install -y php7.1-fpm php7.1-cli php7.1-curl php7.1-mysql php7.1-sqlite3 php7.1-gd php7.1-xml php7.1-mcrypt php7.1-mbstring php7.1-iconv php7.1-cgi php7.1-json

Now open php.ini file

nano /etc/php/7.1/fpm/php.ini

and set


Save and restart php-fpm

service php7.1-fpm restart

Now change NGINX settings. In all files where you include php5-fpm, replace

fastcgi_pass unix:/var/run/php5-fpm.sock;


fastcgi_pass unix:/run/php/php7.1-fpm.sock;

Save and restart NGINX

service nginx restart

Check installed php version. Create file serverinfo.php and write

php -v

Now you have two worked php versions. Check it.

ps aux | grep php

If you don't plan use php5, you can stop it

service php5-fpm stop

To completely remove php5, run commands

apt-get purge php5-common
apt-get purge 'php5*'