Debian/Ubuntu Linux deleting old php 5.6 packages command

Fig.02: Deleting old php 5.6 packages

Fig.02: Deleting old php 5.6 packages

Type the following two commands to delete all install php packages on your server:
x="$(dpkg --list | grep php | awk '/^ii/{ print $2}')"
sudo apt-get --purge remove $x

Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libonig2 libqdbm14
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  libapache2-mod-php5* php-pear* php5* php5-cgi* php5-cli* php5-common*
  php5-fpm* php5-gd* php5-json* php5-mysql* php5-readline*
0 upgraded, 0 newly installed, 11 to remove and 0 not upgraded.
After this operation, 50.1 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 85708 files and directories currently installed.)
Removing php5 (5.6.27+dfsg-0+deb8u1) ...
Removing libapache2-mod-php5 (5.6.27+dfsg-0+deb8u1) ...
php5_invoke prerm: Disable module json for apache2 SAPI
php5_invoke prerm: Disable module mysqli for apache2 SAPI
php5_invoke prerm: Disable module pdo for apache2 SAPI
php5_invoke prerm: Disable module readline for apache2 SAPI
php5_invoke prerm: Disable module pdo_mysql for apache2 SAPI
php5_invoke prerm: Disable module opcache for apache2 SAPI
php5_invoke prerm: Disable module mysql for apache2 SAPI
php5_invoke prerm: Disable module gd for apache2 SAPI
Module php5 disabled.
apache2_invoke prerm: Disable module php5
Purging configuration files for libapache2-mod-php5 (5.6.27+dfsg-0+deb8u1) ...
apache2_invoke postrm: Purging state for php5
Removing php-pear (5.6.27+dfsg-0+deb8u1) ...
Purging configuration files for php-pear (5.6.27+dfsg-0+deb8u1) ...
Removing php5-cgi (5.6.27+dfsg-0+deb8u1) ...
php5_invoke prerm: Disable module json for cgi SAPI
php5_invoke prerm: Disable module mysqli for cgi SAPI
php5_invoke prerm: Disable module pdo for cgi SAPI
php5_invoke prerm: Disable module readline for cgi SAPI
php5_invoke prerm: Disable module pdo_mysql for cgi SAPI
php5_invoke prerm: Disable module opcache for cgi SAPI
php5_invoke prerm: Disable module mysql for cgi SAPI
php5_invoke prerm: Disable module gd for cgi SAPI
apache2_invoke php5-cgi prerm: No action required
Purging configuration files for php5-cgi (5.6.27+dfsg-0+deb8u1) ...
apache2_invoke php5-cgi postrm: No action required
Removing php5-readline (5.6.27+dfsg-0+deb8u1) ...
php5_invoke prerm: Disable module readline for fpm SAPI
php5_invoke prerm: Disable module readline for cli SAPI
Purging configuration files for php5-readline (5.6.27+dfsg-0+deb8u1) ...
Removing php5-fpm (5.6.27+dfsg-0+deb8u1) ...
php5_invoke prerm: Disable module json for fpm SAPI
php5_invoke prerm: Disable module mysqli for fpm SAPI
php5_invoke prerm: Disable module pdo for fpm SAPI
php5_invoke prerm: Disable module pdo_mysql for fpm SAPI
php5_invoke prerm: Disable module opcache for fpm SAPI
php5_invoke prerm: Disable module mysql for fpm SAPI
php5_invoke prerm: Disable module gd for fpm SAPI
Purging configuration files for php5-fpm (5.6.27+dfsg-0+deb8u1) ...
Removing php5-cli (5.6.27+dfsg-0+deb8u1) ...
php5_invoke prerm: Disable module json for cli SAPI
php5_invoke prerm: Disable module mysqli for cli SAPI
php5_invoke prerm: Disable module pdo for cli SAPI
php5_invoke prerm: Disable module pdo_mysql for cli SAPI
php5_invoke prerm: Disable module opcache for cli SAPI
php5_invoke prerm: Disable module mysql for cli SAPI
php5_invoke prerm: Disable module gd for cli SAPI
Purging configuration files for php5-cli (5.6.27+dfsg-0+deb8u1) ...
Removing php5-mysql (5.6.27+dfsg-0+deb8u1) ...
Purging configuration files for php5-mysql (5.6.27+dfsg-0+deb8u1) ...
Removing php5-gd (5.6.27+dfsg-0+deb8u1) ...
Purging configuration files for php5-gd (5.6.27+dfsg-0+deb8u1) ...
Removing php5-json (1.3.6-1) ...
Purging configuration files for php5-json (1.3.6-1) ...
Removing php5-common (5.6.27+dfsg-0+deb8u1) ...
Purging configuration files for php5-common (5.6.27+dfsg-0+deb8u1) ...
dpkg: warning: while removing php5-common, directory '/etc/php5' not empty so not removed
Processing triggers for man-db (2.7.0.2-5) ...

Also run:
apt-get --purge autoremove

Examples and usage: How to install PHP 7 on Debian Linux 8.7/7.x [jessie/wheezy]