This will uninstall all versions of PHP 7, including 7.0, 7.1, and other versions.
sudo apt-get purge php7.*
sudo apt-get autoclean
sudo apt-get autoremove
- apt/apt-get autoclean → cleans obsolete deb-packages, less than clean.
- apt/apt-get autoremove → removes orphaned packages which are no longer needed from the system, but do not purges them, use the --purge option together with the command for that.
Again install PHP using:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
php7.0
sudo apt-get install php7.0
php7.1
sudo apt-get install php7.1
php7.2
sudo apt-get install php7.2
Then enable PHP 7.2:
user@test:~# sudo a2enmod php7.2
sudo service apache2 restart
Install all necessary extensions to ensure future error-free operation. Change the command to match your version. I used 7.2 because I had it installed.
sudo apt install php7.2-common php7.2-mysql php7.2-xml php7.2-xmlrpc php7.2-curl php7.2-gd php7.2-imagick php7.2-cli php7.2-dev php7.2-imap php7.2-mbstring php7.2-opcache php7.2-soap php7.2-zip php7.2-intl -y
I hope this helps you.