Ubuntu: How to completely remove PHP?



Question:

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?


Solution:1

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

sudo apt-get purge php.*  


Solution:2

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

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

sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`  

How it works:

First, a list of packages is generated using this series of commands: dpkg -l | grep php| awk '{print $2}' |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


Solution:3

You'll probably want to purge all the php* packages from your system. Something with a wild-card should work

sudo apt-get purge php.*  

You may be interested in How to rollback to PHP 5.2 for where to go next.


Solution:4

sudo apt-get -y purge libapache2-mod-php5 libapache2-mod-php5filter libexpect-php5 libgv-php5 libow-php5 php5 php5-adodb php5-auth-pam php5-cgi php5-cli php5-common php5-curl php5-dbg php5-enchant php5-exactimage php5-ffmpeg php5-fpm php5-geoip php5-gmp php5-idn php5-imagick php5-imap php5-interbase php5-intl php5-json php5-lasso php5-ldap php5-librdf php5-mapscript php5-memcache php5-memcached php5-mhash php5-midgard2 php5-ming php5-mssql php5-mysql php5-mysqlnd php5-odbc php5-pgsql php5-ps php5-pspell php5-radius php5-recode php5-remctl php5-rrd php5-sasl php5-snmp php5-sqlite php5-suhosin php5-svn php5-sybase php5-tidy php5-tokyo-tyrant php5-uuid php5-xcache php5-xdebug php5-xmlrpc php5-xsl  

In your case, you could search for all the packages:

sudo aptitude search php5|awk {'print $2'}|grep -v i386|grep -v "^A"|tr "\n"  " "  

and then purge them:

sudo apt-get purge <list of packages found>  


Solution:5

First, you have to remove Apache and all of its dependencies with:

sudo apt-get purge apache2 php5 libapache2-mod-php5 mysql-server libapache2-mod-auth-mysql php5-mysql phpmyadmin  

and then:

sudo rm -rf /etc/apache2; rm -rf /etc/php5; rm -rf /var/lib/mysql; rm etc/mysql   

If you have any issues with phpMyAdmin, try entering this into the Terminal:

dpkg-reconfigure phpmyadmin  


Solution:6

In addition to any purges mentioned in the other answers, if you want to be completely sure everything is removed, you're likely to want to run

cd /  sudo find -name "php"  

Which will show you files/folders with the name php in them. You're then going to want to check each of these file paths, i.e.:

cd /usr/local/include/php  ls  

And delete them as is appropriate. Be careful not to delete anything that's critical to another process you need to keep running, though, unless you want to have to reinstall that too.

To remove a directory, or file, we use the rm comment with the -rf flag, so given the above example, we'd type:

sudo rm -rf /usr/local/include/php  

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