41

I have upgraded PHP old version to latest php7 but unable to start its services.

systemctl restart apache2.service

Job for apache2.service failed. See "systemctl status apache2.service" and "journalctl -xe" for details.

Status Detail:

systemctl status apache2.service


● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2)
Active: failed (Result: exit-code) since Mon 2016-01-04 13:58:17 IST; 5s ago
 Docs: man:systemd-sysv-generator(8)
 Process: 16666 ExecStart=/etc/init.d/apache2 start (code=exited,       status=1/FAILURE)

Jan 04 13:58:17 GCT022 apache2[16666]: *
Jan 04 13:58:17 GCT022 apache2[16666]: * The apache2 configtest failed.
Jan 04 13:58:17 GCT022 apache2[16666]: Output of config test was:
Jan 04 13:58:17 GCT022 apache2[16666]: apache2: Syntax error on line 140 of /etc/apache2...
Jan 04 13:58:17 GCT022 apache2[16666]: Action 'configtest' failed.
Jan 04 13:58:17 GCT022 apache2[16666]: The Apache error log may have more information.
Jan 04 13:58:17 GCT022 systemd[1]: apache2.service: control process exited, code=exit...s=1
Jan 04 13:58:17 GCT022 systemd[1]: Failed to start LSB: Apache2 web server.
Jan 04 13:58:17 GCT022 systemd[1]: Unit apache2.service entered failed state.
Jan 04 13:58:17 GCT022 systemd[1]: apache2.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
root@client022:/home/user22$ ^C

Now I want to revert back or remove php7 that i can do the user machine active with the old version.

7 Answers 7

111

To remove php7.0 use

sudo apt-get purge php7.0-common
0
37

This will remove all php7 version, be it php 7.0 or php 7.1 etc..

sudo apt-get purge php7.*
4
  • 4
    Shouldn't that be sudo apt-get purge php7.* ?
    – kurdtpage
    Commented Jan 19, 2017 at 20:45
  • This also purged my php5.
    – pbond
    Commented Mar 3, 2017 at 15:01
  • @kurdtpage +1 I tried it again and yes it did purged php5. also, don't know why though that was not the case earlier . Commented Mar 14, 2017 at 7:04
  • @AbhishekPareek the * is a regex star, not a glob star. Commented Apr 17, 2018 at 22:48
12

As I have answered your question Unable to locate package php7.0 and you have accepted my answer and because you explicitly ask for a removal of the package:

sudo apt-get install ppa-purge
sudo ppa-purge ppa:ondrej/php-7.0
3
  • It was installed all the packages and I have checked day its PHP-v it was Ok Shutdown the System today, just checked that php7 unable start services so maybe it is the different issue. Commented Jan 4, 2016 at 8:54
  • $ sudo ppa-purge ppa:ondrej/php-7.0 sudo: ppa-purge: command not found Commented Jan 4, 2016 at 8:57
  • Answer updated.
    – A.B.
    Commented Jan 4, 2016 at 8:58
5

If you run Abhishek's it will remove other packages. On mine it was going to remove these too

The following packages will be REMOVED

libapache2-mod-php5.5* libapache2-mod-php5.6* php-common* php-gettext* php-igbinary* php-memcached* php-msgpack* php-pear* php-xdebug* php5-cli*
php5-common* php5-dev* php5-json* php5-memcache* php5-memcached*
php5-readline* php5-redis* php5-xdebug* php5.5-cli* php5.5-common*
php5.5-curl* php5.5-json* php5.5-mysql* php5.5-opcache* php5.5-readline* php5.5-xml* php5.6* php5.6-cli* php5.6-common* php5.6-curl* php5.6-fpm* php5.6-json* php5.6-mbstring* php5.6-mysql* php5.6-opcache* php5.6-readline* php5.6-xml* pkg-php-tools*

So you're better off with

sudo apt-get purge php7.*
5

to remove php7.x simpely use

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

The way to remove PHP and dependencies is:

apt-get autoremove php7.0
4
  • This is the same as most of the other answers.
    – fosslinux
    Commented Apr 17, 2018 at 4:26
  • 1
    I don't think any of the other answers suggest precisely this...
    – Zanna
    Commented Apr 17, 2018 at 6:14
  • 1
    @Zanna You are right. Moreover, this seems to work on my Ubuntu 16.04 but giving a package name to apt-get autoremove is not documented in the man page.
    – Melebius
    Commented Apr 18, 2018 at 7:29
  • 1
    @Melebius yes it works for me on 17.10 too - autoremove in place of remove causes the orphaned dependencies to be removed at the same time, which saves running an additional command. I don't know why it is not documented as it's very useful!
    – Zanna
    Commented Apr 18, 2018 at 7:38
2

After doing a:

sudo apt-get purge php7.*

to remove all versions of php7, you still need to run some extra steps to completely and utterly remove php7:

sudo apt-get autoremove --purge

Then do a:

whereis php

and then remove all directories in the output of the last command, E.G.:

sudo rm -rf /etc/php

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .