I have a server that has an application that runs with PHP 5.6. But I upgraded the server from Ubuntu 14.04 to 18.04 and in the process I also upgraded PHP to 7.2.
Now I’m trying to uninstall it but I’m finding difficult.
I have run the command:
sudo apt-get remove php
and
sudo apt-get remove --purge php
Its says that PHP it’s not installed, but running
php --version
I’m still seeing the version 7 of PHP.
PHP 7.2.19-0ubuntu0.18.04.2 (cli) (built: Aug 12 2019 19:34:28) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.19-0ubuntu0.18.04.2, Copyright (c) 1999-2018, by Zend Technologies
7
Answers
This will remove all php7 versions, be it php 7.0 or php 7.1 etc..
apt/apt-get autoclean
→ cleans obsolete deb-packages, less thanclean
apt/apt-get autoremove
→ removes orphaned packages which are not longer needed from the system, but not purges them, use the--purge
option together with the command for that.**To Install PHP again **
if php7.0
if php7.1
if php7.2
To switch that to the newer 7.1,7.2,7.3,7.4 version, first disable older PHP version:
Then enable PHP 7.2:
Install all the required extension, so it won’t make any error in future.
Replace command based on your version. I used 7.2 as I have installed that version.
Firstly you need to restart the apache to take all in effect and also
You can install mutliple php version using this post
or just using
disable php7.2:
enable php 5.6:
After all restart the apache again to take into affect
This is work on my server:
This will remove PHP
To uninstall PHP
The output of the below command will provide you with information on the installed package software, version, architecture, and a short description of the package. grep command is used to find the PHP package
sudo apt-get remove –purge
sudo whereis php
sudo rm -rf <directory/file path from the previous command output>
apt-mark to the rescue
I think it is a good idea to point out the existence of
apt-mark hold <package-name>
.Once you have a specific version installed that you want to keep, you can prevent accidental upgrades. So you can run
apt upgrade
,apt full-upgrade
and don’t need to worry about which PHP version you will end up with.That said, you also prevent scenarios (as seen with the commenters above) where you end up with multiple major and main releases installed next to each other at the same time.
For example, if you have PHP 7.4 installed, and your App doesn’t support PHP 8.* yet, then:
Just run
sudo apt-get purge 'php*'