I'll split my answer into two parts. The first part describes how your problem occurred, the second part is the actual answer to your issue.
Disclaimer: Most of my description is basically speculation, as I cannot really know what you did. But it's the most likely scenario, as I cannot think of another way that would end up giving you the issue you described.
From the problem you describe, it seems you have installed a third party PPA which installed PHP 7.1 on your system. The most likely PPA is Ondrej's PPA.
When you first installed PHP, you installed in the following method:
sudo apt install php
php package is only a meta package and does not contain the binaries needed. It depends on the latest version of the available PHP package (by default 7.0). So when you install it, the
php7.0 package is installed along with
php7.0's dependencies (and
if you have
apache2) and all those dependencies are marked in the package manager as "automatically installed".
$ apt show php
Source: php-defaults (35ubuntu6)
Maintainer: Ubuntu Developers
Original-Maintainer: Debian PHP Maintainers
Installed-Size: 11.3 kB
Download-Size: 2,832 B
APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
open source general-purpose scripting language that is especially suited
for web development and can be embedded into HTML.
This package is a dependency package, which depends on Debian's default
PHP version (currently 7.0).
I bolded the parts of the command's result, which explains what I just mentioned.
Ondrej's PHP PPA offers multiple PHP versions that can be installed alongside each other. So when you added it your system,
apt found a newer version of PHP so it replaced
php7.1 along with any related packages that were automatically installed.
There are two methods to fix your issues.
Completely remove the 3rd party PPA, and revert back to the default PHP packages
sudo apt install ppa-purge
sudo ppa-purge ppa:ondrej/php
Ondrej's PPA offers multiple versions of PHP, so you can install more than one version along side each other. But you would enable only the
php7.0 Apache module.
sudo apt install php7.0 libapache2-mod-php7.0
sudo a2dismod php7.1
sudo a2enmod php7.0
sudo apache2ctl restart
Installing them in the previous manner would set the
php7.0 package as "manually installed" in
apt, so they won't get removed automatically without you removing them yourself.
Don't forget to make sure to install any PHP modules you need for php7.0 as well (Like
sudo apt install php7.0-mysql)
php7.0 may have been kept in your system installed if you had manually installed a module specifically for php7.0 (for example