Ubuntu: How to completly remove php libraries?



Question:

I use zsh. when I try to upgrade the system, some packages related to php pop up, I want to remove them

 sudo apt-get upgrade                Reading package lists... Done  Building dependency tree         Reading state information... Done  Calculating upgrade... Done  The following packages will be upgraded:    fonts-opensymbol kdelibs-bin kdelibs5-data kdelibs5-plugins kdoctools    libkcmutils4 libkde3support4 libkdeclarative5 libkdecore5 libkdesu5    libkdeui5 libkdewebkit5 libkdnssd4 libkemoticons4 libkfile4 libkhtml5    libkidletime4 libkio5 libkjsapi4 libkjsembed4 libkmediaplayer4    libknewstuff3-4 libknotifyconfig4 libkntlm4 libkparts4 libkprintutils4    libkpty4 libkrosscore4 libktexteditor4 libnepomuk4 libnepomukquery4a    libnepomukutils4 libplasma3 libsolid4 libssl1.0.0 libssl1.0.0:i386    libthreadweaver4 openssl php-pear php5-cli php5-common php5-curl php5-fpm    php5-gd php5-intl php5-mysql php5-pspell php5-readline php5-recode php5-snmp    php5-sqlite php5-tidy php5-xmlrpc php5-xsl  54 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.  Need to get 18.4 MB/20.0 MB of archives.  After this operation, 0 B of additional disk space will be used.  Do you want to continue? [Y/n]   

What I tried:

 sudo apt-get remove php  Reading package lists... Done  Building dependency tree         Reading state information... Done  E: Unable to locate package php    â–¶ sudo apt-get remove php*  zsh: no matches found: php*    sudo apt-get remove php *  Reading package lists... Done  Building dependency tree         Reading state information... Done  Package 'dropbox' is not installed, so not removed  E: Unable to locate package php  E: Unable to locate package avlfolder  E: Unable to locate package boot-scripts  E: Unable to locate package Calibre Library  E: Unable to locate package Desktop  E: Unable to locate package Documents  E: Unable to locate package Downloads  E: Unable to locate package Dungeons and Dragons Online  E: Unable to locate package Games  E: Unable to locate package java ide  E: Unable to locate package jdownloader  E: Unable to locate package lello  E: Unable to locate package liberam  E: Unable to locate package Music  E: Unable to locate package netbeans-8.0  E: Couldn't find any package by regex 'netbeans-8.0'  E: Unable to locate package netbeans-8.0.desktop  E: Couldn't find any package by regex 'netbeans-8.0.desktop'  E: Unable to locate package Pictures  E: Unable to locate package PlayOnLinux's virtual drives  E: Unable to locate package projects  E: Unable to locate package Public  E: Unable to locate package qtprojects  E: Unable to locate package Savage2  E: Unable to locate package sketchbook  E: Unable to locate package Templates  E: Unable to locate package text.txt  E: Couldn't find any package by regex 'text.txt'  E: Unable to locate package themes  E: Unable to locate package tor-browser-linux64-3.6.1_en-US.tar.xz  E: Couldn't find any package by regex 'tor-browser-linux64-3.6.1_en-US.tar.xz'  E: Unable to locate package Videos  E: Unable to locate package VirtualBox VMs  E: Unable to locate package workspace  E: Unable to locate package xal  

And I tried the same with php5 and with purge, nothing has changed. autoremove didn't work either

Update

Since I had no answer so far, I ran

sudo apt-get remove --purge php-pear php5-cli php5-common php5-curl php5-fpmphp5-gd php5-intl php5-mysql php5-pspell php5-readline php5-recode php5-snmpphp5-sqlite php5-tidy php5-xmlrpc php5-xsl  [sudo] password for elie:   Reading package lists... Done  Building dependency tree         Reading state information... Done  E: Unable to locate package php5-fpmphp5-gd  E: Unable to locate package php5-snmpphp5-sqlite  

I was looking for a better solution, anyway I don't understand how php5-fpmphp5-gd and php5-snmpphp5-sqlite need to be upgraded if they aren't installed. How could the system detect that they need to be upgraded, but didn't detect them when I tried to remove them?


Solution:1

zsh, unlike bash, has a different glob/wildcard/expansion system, so it works differently so php*might not work as you expect.
So are instead of sudo apt-get remove php*, you could:

  • Quote it:

    sudo apt-get remove "php*"  
  • Bash it:

    bash -c "sudo apt-get remove php*"  

N.B. Whilst also being a bad idea (as previously pointed out), sudo apt-get remove php * returned the names of files and foldersin the current working directory (likely your home directory) because of the * - but this also means if you have any files in hte terminal's current working directory beginning with php, you may have a problem using php* to request stuff, as it might include those filenames in the expansion.

Another N.B. php5-fpmphp5-gd and php5-snmpphp5-sqlite might of been part of the update, as some of the packages being updated needed those packages as new dependencies. By php5-fpmphp5-gd and php5-snmpphp5-sqlite, you probably meant php5-fpm, php5-gd, php5-snmp, php5-sqlite... (looking at the output you provided, it was because newlines occurred at those points) you probably should of ran:

sudo apt-get remove --purge php-pear php5-cli php5-common php5-curl php5-fpm php5-gd php5-intl php5-mysql php5-pspell php5-readline php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl  


Solution:2

aptitude is an alternative to apt-get which makes it easy to match multiple package names using regular-expression-like patterns.

For example, to list all installed packages whose package names contain the term "php":

aptitude search ~iphp  

Edit: when using zsh shell, quote the argument so it doesn't break on the tilde:

sudo aptitude search "~iphp"  

Or to uninstall them:

sudo aptitude remove ~iphp  

or

sudo aptitude purge ~iphp  

Consult this reference for more on the aptitude search syntax.

Note: aptitude is more powerful than apt-get and therefore makes it easier to hose your system. Always check which packages it is planning to remove, install, or downgrade before you confirm that it should go ahead. For example, sometimes in order to satisfy your request to uninstall a package, aptitude would need to uninstall a bunch of other packages that depend on it.

If you're wondering what caused php packages to be installed in the first place, you can do some detective work by searching for reverse dependencies for a package: which packages depend on a package. Recommended dependencies are installed by default but it is possible to override this and install a package without its "recommends" dependencies, or remove some "recommends" dependencies without removing the original package.

To list packages which are currently installed which also depend on, say, php5-fpm:

aptitude why php5-fpm  

This should work most of the time, but for various reasons sometimes it can be impossible for the system to tell what caused a package to be automatically installed - maybe it was once a dependency of something but after an upgrade it's no longer depended on, etc.

If you get a command not found when trying to use aptitude, you need to install it on your system, like this:

sudo apt-get install aptitude  

Note: in the past, it was common to warn people not to use apt-get and aptitude interchangeably to actually modify the system, because they couldn't keep track of which packages were automatically installed by each other. This is no longer an issue (since at least 3 years ago), and they both use the same way of recording which packages were automatically installed.

Edit: fixed aptitude why command


Solution:3

you can use purge, autoremove & remove 'i am using autoremove as an example for this'

$ sudo apt-get autoremove php*  

you can also use aptitude

$ sudo aptitude remove php*  

check the installed packages

$ sudo apt-cahe policy php*  

if all of them are none so all of the php app aren't installed

if there's an installed package you can delete it by

$ sudo apt-get autoremove 'packagename'  


Solution:4

Use this command for your issue :

sudo apt-get -y purge php*  


Solution:5

If you have Apache (or some other web server), you can put this code in the Apache root directory (usually /var/www/) in a file called [somename].php:

<?php            phpinfo();    ?>  

Then, you can access it from a web browser by going to http://localhost/[somename].php. If that file runs, it will let you know if and what version of php is installed on the system. You can also run this command:

apt-cache policy php5  

to see if you have php5 installed.

If those commands show that php is installed, you should be able to remove it using:

apt-get purge php*  

If those commands do not show php installed, then it is probably being upgraded as a dependency of another package. Sometimes, they do not show as newly installed (I have no idea why).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »