Как удалить php ubuntu

от admin

Uninstall php 7 in ubuntu 18.04

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

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 7

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 than clean
  • 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

After all restart the apache again to take into affect

This will remove PHP

Kourosh Neyestani's user avatar

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>

Just run

sudo apt-get purge ‘php*’

Ayman Elshehawy's user avatar

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:

How to uninstall PHP in Ubuntu?

Uninstalling PHP in Ubuntu is quite easy and straightforward. Let us consider we have PHP version 7.0 and we want to remove it from Ubuntu.

The following command will remove PHP from Ubuntu:

apt/apt-get autoclean → cleans obsolete deb-packages, less than clean
apt/apt-get autoremove → removes orphaned packages that are no longer needed from the system, but not purges them, use the –purge option together with the command for that.

How to completely remove PHP?

I need to clean up my server from PHP 5.3 packages (there are plenty of them) in order to be able to compile PHP 5.2. What is the easiest/safest method to get rid of them all?

10 Answers 10

This method is not advised to be used without careful review. Read below comments.

This should completely remove any package with a name that starts with php and anything related to it.

DON’T PRESS y UNTIL YOU ENSURE that in the removing packages list there are no other packages (besides related to php packages), like:

php-common* python-openssl* php-curl* . and tons of packages

If so, type n , copy the list (& tidy up from the unrelated packages), and manually remove them:

T.Todua's user avatar

I do not recommend running sudo apt-get purge php* .

Читать:
Как установить k lite codec pack

That was scary! Fortunately, I didn’t type the -y option, because it chose about hundred of packages without php in their name.

How it works:

First, a list of packages is generated using this series of commands: dpkg -l | grep php| awk ‘‘ |tr «\n» » » .

Hint: You can run this part of the command in your terminal to see what packages would get removed. You should get something like: libapache2-mod-php5 php5 php5-cli php5-common php5-json

Finally, when you run the full command, this list of packages gets passed to sudo apt-get purge, removing all of the packages.

Hint: If it feels safer to you, you could just as easily run them separately, and copy+paste the list of packages to remove like so: sudo apt-get purge libapache2-mod-php5 php5 php5-cli php5-common php5-json

PHP Developer

My notes and thoughts about Linux, WordPress, PHP and many more.

How to completely remove PHP, MySQL and Apache in Ubuntu 16.04+

Reasons why you would want to do this
  • Local Apache/MySQL/PHP not working after upgrade to Ubuntu 16.04
  • Local Server beyond repair, diagnosing issues takes too much time
  • Simply want to completely remove LAMPP installation in order to have a fresh installation.
Requirements and scope

Important: Please run:

Before you proceed with anything else.

  • Tested in Ubuntu 16.04+, if you are using an older Ubuntu versions. This may not guaranteed to work
  • You want to completely remove PHP, MySQL and Apache in your local server environment
  • This is not designed to removed Nginx installations.
  • This is not tested to work in other operating systems like Mac, Windows or other Linux distributions except Ubuntu.
  • You need to have root access to your Ubuntu local server.
  • Make sure you install this first:
  • You need git run this uninstall software:
Preparations to make before removal
  1. Backup your existing website files and database – make sure you do a dB dump of every site you are working on locally and put them in the safe place like your Desktop or external drive. This uninstallation procedure completely removes your MySQL including all databases! I recommend that you test your backup to make sure it works ��
  2. Now you have a backup, closely examine your MySQL database, there might be databases there that are used for sites but you still need it. Make sure you have a backup it also.
  3. In your Ubuntu 16.04 attempt to update to the very latest packages. In the command line run these two simple commands:
Complete uninstallation procedures
  1. Clone this repo to your local Desktop:
  2. Get inside the scripts directory:
  3. Make sure installer scripts are executable:
  4. Login as root:
  5. Run the LAMPP uninstaller:

At this point, you can safely re-install latest PHP, MySQL, Apache again in your Ubuntu 16.04. If something in this tutorial does not work, let me know and I will update the uninstallation scripts.

3 thoughts on How to completely remove PHP, MySQL and Apache in Ubuntu 16.04+

Hi, thanx but issues when i try to reinstall lamp :
“Paramétrage de mariadb-common (10.1.37-0+deb9u1) …
update-alternatives: erreur: le chemin alternatif /etc/mysql/mariadb.cnf n’existe pas
dpkg: erreur de traitement du paquet mariadb-common (–configure) :
le sous-processus script post-installation installé a retourné une erreur de sortie d’état 2
Des erreurs ont été rencontrées pendant l’exécution :
mariadb-common
E: Sub-process /usr/bin/dpkg returned an error code (1)”

It seems you are using Maria dB, this tutorial assumes you are using MySQL database. I think it would work if you replace mysql-common with equivalent mariadb-common. But I have not tested this , so I would recommend to get help somewhere else or read other resources. Thanks for dropping by!

Thank you for this script, it helped me a lot after I messed up my LAMP server.

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Похожие статьи