rramirezm
By:
rramirezm

Trying to uninstall phpmyadmin "dpkg: error while cleaning up:"

February 5, 2017 2.3k views
Linux Commands Ubuntu 16.04

When I'm trying to uninstall phpmyadmin by typing:

sudo apt-get remove phpmyadmin*

I get this:

Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'phpmyadmin' for glob 'phpmyadmin*'
The following packages were automatically installed and are no longer required:
  dbconfig-common dbconfig-mysql javascript-common libjs-jquery libjs-sphinxdoc libjs-underscore libmcrypt4
  linux-headers-4.4.0-57 linux-headers-4.4.0-57-generic linux-image-4.4.0-57-generic php-gd php-mcrypt
  php-phpseclib php-tcpdf php7.0-gd php7.0-mcrypt
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  phpmyadmin
0 upgraded, 0 newly installed, 1 to remove and 54 not upgraded.
1 not fully installed or removed.
After this operation, 25.0 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 124123 files and directories currently installed.)
Removing phpmyadmin (4:4.5.4.1-2ubuntu2) ...
/var/lib/dpkg/info/phpmyadmin.prerm: 44: /etc/dbconfig-common/phpmyadmin.conf: Syntax error: "(" unexpected
dpkg: error processing package phpmyadmin (--remove):
 subprocess installed pre-removal script returned error exit status 2
/var/lib/dpkg/info/phpmyadmin.config: 44: /etc/dbconfig-common/phpmyadmin.conf: Syntax error: "(" unexpected
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
 phpmyadmin
E: Sub-process /usr/bin/dpkg returned an error code (1)

3 Answers

@rramirezm

Have you tried running without the glob (i.e. using the asterisk)?

sudo apt-get remove phpmyadmin

or simply purging the package:

sudo apt-get purge phpmyadmin

If neither of those work, you may want to run:

sudo apt-get -f install

... and then try running them again. The above will attempt to resolve any dependencies that may otherwise exist.

You can also run:

sudo apt autremove

... to remove the packages listed in the output since they are no longer in use/needed.

If nothing seems to be working, we can remove the dpkg files manually:

rm -r /var/lib/dpkg/info/phpmyadmin.*

... then run:

sudo apt-get clean \
&& sudo apt-get update \
&& sudo apt-get remove phpmyadmin \
&& sudo apt-get purge phpmyadmin
  • Hi @jtittle,
    sudo apt-get remove phpmyadmin, sudo apt-get purge phpmyadmin, sudo apt-get -f install returned the same error:

     subprocess installed pre-removal script returned error exit status 2
    /var/lib/dpkg/info/phpmyadmin.config: 44: /etc/dbconfig-common/phpmyadmin.conf: Syntax error: "(" unexpected
    dpkg: error while cleaning up:
     subprocess installed post-installation script returned error exit status 2
    Errors were encountered while processing:
     phpmyadmin
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    

    The final step seemed to work

    Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
    Hit:2 http://nyc2.mirrors.digitalocean.com/ubuntu xenial InRelease
    Get:3 http://nyc2.mirrors.digitalocean.com/ubuntu xenial-updates InRelease [102 kB]
    Get:4 http://nyc2.mirrors.digitalocean.com/ubuntu xenial-backports InRelease [102 kB]
    Hit:5 https://deb.nodesource.com/node_6.x xenial InRelease
    Hit:6 https://repos.sonar.digitalocean.com/apt main InRelease
    Fetched 306 kB in 1s (266 kB/s)
    Reading package lists... Done
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
      dbconfig-common dbconfig-mysql javascript-common libjs-jquery libjs-sphinxdoc libjs-underscore libmcrypt4
      php-gd php-mcrypt php-phpseclib php-tcpdf php7.0-gd php7.0-mcrypt
    Use 'sudo apt autoremove' to remove them.
    The following packages will be REMOVED:
      phpmyadmin
    0 upgraded, 0 newly installed, 1 to remove and 54 not upgraded.
    1 not fully installed or removed.
    After this operation, 25.0 MB disk space will be freed.
    Do you want to continue? [Y/n] y
    (Reading database ... 94663 files and directories currently installed.)
    Removing phpmyadmin (4:4.5.4.1-2ubuntu2) ...
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
      dbconfig-common dbconfig-mysql javascript-common libjs-jquery libjs-sphinxdoc libjs-underscore libmcrypt4
      php-gd php-mcrypt php-phpseclib php-tcpdf php7.0-gd php7.0-mcrypt
    Use 'sudo apt autoremove' to remove them.
    The following packages will be REMOVED:
      phpmyadmin*
    0 upgraded, 0 newly installed, 1 to remove and 54 not upgraded.
    After this operation, 0 B of additional disk space will be used.
    Do you want to continue? [Y/n] y
    (Reading database ... 94663 files and directories currently installed.)
    Removing phpmyadmin (4:4.5.4.1-2ubuntu2) ...
    Purging configuration files for phpmyadmin (4:4.5.4.1-2ubuntu2) ...
    

    Now I should be able to reinstall it am I right?

    • @rramirezm

      Yes, though I would run apt-get update once again to ensure that all packages are synced before running apt-get install.

      • Oh no It's back after running apt-get update and apt-get install phpmyadmin I got this:

        Reading package lists... Done
        Building dependency tree
        Reading state information... Done
        Suggested packages:
          www-browser
        The following NEW packages will be installed:
          phpmyadmin
        0 upgraded, 1 newly installed, 0 to remove and 54 not upgraded.
        Need to get 3,934 kB of archives.
        After this operation, 25.0 MB of additional disk space will be used.
        Get:1 http://nyc2.mirrors.digitalocean.com/ubuntu xenial-updates/universe amd64 phpmyadmin all 4:4.5.4.1-2ubuntu2 [3,934 kB]
        Fetched 3,934 kB in 1s (3,742 kB/s)
        Preconfiguring packages ...
        /tmp/phpmyadmin.config.HSqQcN: 44: /etc/dbconfig-common/phpmyadmin.conf: Syntax error: "(" unexpected
        phpmyadmin failed to preconfigure, with exit status 2
        Selecting previously unselected package phpmyadmin.
        (Reading database ... 94663 files and directories currently installed.)
        Preparing to unpack .../phpmyadmin_4%3a4.5.4.1-2ubuntu2_all.deb ...
        Unpacking phpmyadmin (4:4.5.4.1-2ubuntu2) ...
        Processing triggers for man-db (2.7.5-1) ...
        Setting up phpmyadmin (4:4.5.4.1-2ubuntu2) ...
        /var/lib/dpkg/info/phpmyadmin.config: 44: /etc/dbconfig-common/phpmyadmin.conf: Syntax error: "(" unexpected
        dpkg: error processing package phpmyadmin (--configure):
         subprocess installed post-installation script returned error exit status 2
        Errors were encountered while processing:
         phpmyadmin
        E: Sub-process /usr/bin/dpkg returned an error code (1)
        
        
        • @rramirezm

          Try running the same again to clean it up:

          sudo rm -r /var/lib/dpkg/info/phpmyadmin.* \
          && sudo apt-get clean \
          && sudo apt-get update \
          && sudo apt-get remove phpmyadmin \
          && sudo apt-get purge phpmyadmin
          

          Then:

          sudo apt-get update \
          sudo apt-get -f install \
          sudo apt autoremove
          

          We can also run:

          dpkg --purge --force-remove-reinstreq phpmyadmin
          

          That'll clean up phpMyAdmin as well as any other packages that are no longer in use.

          I spun up a fresh DigitalOcean Droplet to test the phpmyadmin package with an instance of Apache2 and MySQL and the installation went fine, as long as I first installed mysql-server.

          So what I did was run:

          sudo apt-get update \
          && sudo apt-get -y upgrade \
          && sudo apt-get -y install mysql-server
          

          Then I ran:

          sudo apt-get -y install phpmyadmin
          

          So the best way to get this straightened out would be to either:

          1). Perform a re-image on the Droplet, if you don't have an current data on it, or;

          2). Run the following after you've ran the above to clean up phpmyadmin:

          sudo apt-get -y purge mysql* apache*
          

          With them both wiped off the Droplet, install MySQL first and then phpMyAdmin. Previously, the phpMyAdmin package seemed to handle the complete installation just fine, though that doesn't seem to be the case. I'm not sure if they've changed how the package runs or if it's a fluke, but installing MySQL first and then phpMyAdmin works.

          • I'm using Nginx not apache

          • I have run:

            sudo rm -r /var/lib/dpkg/info/phpmyadmin.* \
            && sudo apt-get clean \
            && sudo apt-get update \
            && sudo apt-get remove phpmyadmin \
            && sudo apt-get purge phpmyadmin
            
            sudo apt-get update \
            sudo apt-get -f install \
            sudo apt autoremove
            
            dpkg --purge --force-remove-reinstreq phpmyadmin
            
            sudo apt-get -y purge mysql* 
            
            

            And followed this guide:
            https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-16-04
            To reinstall mysql, and everything looked good. But when I reinstalled phpmyadmin with sudo apt-get -y install phpmyadmin this was the verbose:

            Reading package lists... Done
            Building dependency tree
            Reading state information... Done
            The following additional packages will be installed:
              dbconfig-common dbconfig-mysql javascript-common libjs-jquery libjs-sphinxdoc libjs-underscore libmcrypt4
              php-gd php-mcrypt php-phpseclib php-tcpdf php7.0-gd php7.0-mcrypt
            Suggested packages:
              libmcrypt-dev mcrypt php-libsodium php-gmp php-imagick www-browser
            The following NEW packages will be installed:
              dbconfig-common dbconfig-mysql javascript-common libjs-jquery libjs-sphinxdoc libjs-underscore libmcrypt4
              php-gd php-mcrypt php-phpseclib php-tcpdf php7.0-gd php7.0-mcrypt phpmyadmin
            0 upgraded, 14 newly installed, 0 to remove and 54 not upgraded.
            Need to get 13.0 MB of archives.
            After this operation, 49.3 MB of additional disk space will be used.
            Get:1 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/main amd64 dbconfig-common all 2.0.4ubuntu1 [582 kB]
            Get:2 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/universe amd64 dbconfig-mysql all 2.0.4ubuntu1 [1,038 B]
            Get:3 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/main amd64 javascript-common all 11 [6,066 B]
            Get:4 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/main amd64 libjs-jquery all 1.11.3+dfsg-4 [161 kB]
            Get:5 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/main amd64 libjs-underscore all 1.7.0~dfsg-1ubuntu1 [46.7 kB]
            Get:6 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/main amd64 libjs-sphinxdoc all 1.3.6-2ubuntu1 [57.5 kB]
            Get:7 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/universe amd64 libmcrypt4 amd64 2.5.8-3.3 [63.0 kB]
            Get:8 http://nyc2.mirrors.digitalocean.com/ubuntu xenial-updates/main amd64 php7.0-gd amd64 7.0.13-0ubuntu0.16.04.1 [27.4 kB]
            Get:9 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/main amd64 php-gd all 1:7.0+35ubuntu6 [1,928 B]
            Get:10 http://nyc2.mirrors.digitalocean.com/ubuntu xenial-updates/universe amd64 php7.0-mcrypt amd64 7.0.13-0ubuntu0.16.04.1 [14.5 kB]
            Get:11 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/universe amd64 php-mcrypt all 1:7.0+35ubuntu6 [1,930 B]
            Get:12 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/universe amd64 php-phpseclib all 2.0.1-1build1 [173 kB]
            Get:13 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/universe amd64 php-tcpdf all 6.0.093+dfsg-1ubuntu1 [7,881 kB]
            Get:14 http://nyc2.mirrors.digitalocean.com/ubuntu xenial-updates/universe amd64 phpmyadmin all 4:4.5.4.1-2ubuntu2 [3,934 kB]
            Fetched 13.0 MB in 2s (6,435 kB/s)
            Preconfiguring packages ...
            Selecting previously unselected package dbconfig-common.
            (Reading database ... 93985 files and directories currently installed.)
            Preparing to unpack .../dbconfig-common_2.0.4ubuntu1_all.deb ...
            Unpacking dbconfig-common (2.0.4ubuntu1) ...
            Selecting previously unselected package dbconfig-mysql.
            Preparing to unpack .../dbconfig-mysql_2.0.4ubuntu1_all.deb ...
            Unpacking dbconfig-mysql (2.0.4ubuntu1) ...
            Selecting previously unselected package javascript-common.
            Preparing to unpack .../javascript-common_11_all.deb ...
            Unpacking javascript-common (11) ...
            Selecting previously unselected package libjs-jquery.
            Preparing to unpack .../libjs-jquery_1.11.3+dfsg-4_all.deb ...
            Unpacking libjs-jquery (1.11.3+dfsg-4) ...
            Selecting previously unselected package libjs-underscore.
            Preparing to unpack .../libjs-underscore_1.7.0~dfsg-1ubuntu1_all.deb ...
            Unpacking libjs-underscore (1.7.0~dfsg-1ubuntu1) ...
            Selecting previously unselected package libjs-sphinxdoc.
            Preparing to unpack .../libjs-sphinxdoc_1.3.6-2ubuntu1_all.deb ...
            Unpacking libjs-sphinxdoc (1.3.6-2ubuntu1) ...
            Selecting previously unselected package libmcrypt4.
            Preparing to unpack .../libmcrypt4_2.5.8-3.3_amd64.deb ...
            Unpacking libmcrypt4 (2.5.8-3.3) ...
            Selecting previously unselected package php7.0-gd.
            Preparing to unpack .../php7.0-gd_7.0.13-0ubuntu0.16.04.1_amd64.deb ...
            Unpacking php7.0-gd (7.0.13-0ubuntu0.16.04.1) ...
            Selecting previously unselected package php-gd.
            Preparing to unpack .../php-gd_1%3a7.0+35ubuntu6_all.deb ...
            Unpacking php-gd (1:7.0+35ubuntu6) ...
            Selecting previously unselected package php7.0-mcrypt.
            Preparing to unpack .../php7.0-mcrypt_7.0.13-0ubuntu0.16.04.1_amd64.deb ...
            Unpacking php7.0-mcrypt (7.0.13-0ubuntu0.16.04.1) ...
            Selecting previously unselected package php-mcrypt.
            Preparing to unpack .../php-mcrypt_1%3a7.0+35ubuntu6_all.deb ...
            Unpacking php-mcrypt (1:7.0+35ubuntu6) ...
            Selecting previously unselected package php-phpseclib.
            Preparing to unpack .../php-phpseclib_2.0.1-1build1_all.deb ...
            Unpacking php-phpseclib (2.0.1-1build1) ...
            Selecting previously unselected package php-tcpdf.
            Preparing to unpack .../php-tcpdf_6.0.093+dfsg-1ubuntu1_all.deb ...
            Unpacking php-tcpdf (6.0.093+dfsg-1ubuntu1) ...
            Selecting previously unselected package phpmyadmin.
            Preparing to unpack .../phpmyadmin_4%3a4.5.4.1-2ubuntu2_all.deb ...
            Unpacking phpmyadmin (4:4.5.4.1-2ubuntu2) ...
            Processing triggers for man-db (2.7.5-1) ...
            Processing triggers for php7.0-fpm (7.0.13-0ubuntu0.16.04.1) ...
            Setting up dbconfig-common (2.0.4ubuntu1) ...
            Setting up dbconfig-mysql (2.0.4ubuntu1) ...
            Setting up javascript-common (11) ...
            Setting up libjs-jquery (1.11.3+dfsg-4) ...
            Setting up libjs-underscore (1.7.0~dfsg-1ubuntu1) ...
            Setting up libjs-sphinxdoc (1.3.6-2ubuntu1) ...
            Setting up libmcrypt4 (2.5.8-3.3) ...
            Setting up php7.0-gd (7.0.13-0ubuntu0.16.04.1) ...
            Setting up php-gd (1:7.0+35ubuntu6) ...
            Setting up php7.0-mcrypt (7.0.13-0ubuntu0.16.04.1) ...
            Setting up php-mcrypt (1:7.0+35ubuntu6) ...
            Setting up php-phpseclib (2.0.1-1build1) ...
            Setting up php-tcpdf (6.0.093+dfsg-1ubuntu1) ...
            Setting up phpmyadmin (4:4.5.4.1-2ubuntu2) ...
            /var/lib/dpkg/info/phpmyadmin.config: 44: /etc/dbconfig-common/phpmyadmin.conf: Syntax error: "(" unexpected
            dpkg: error processing package phpmyadmin (--configure):
             subprocess installed post-installation script returned error exit status 2
            Processing triggers for libc-bin (2.23-0ubuntu5) ...
            Processing triggers for php7.0-fpm (7.0.13-0ubuntu0.16.04.1) ...
            Errors were encountered while processing:
             phpmyadmin
            E: Sub-process /usr/bin/dpkg returned an error code (1)
            
            MySQL is an open-source database management system, commonly installed as part of the popular LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack. It uses a relational database and SQL (Structured Query Language) to manage its data. This tutorial will explain how to install MySQL version 5.7 on a Ubuntu 16.04 server. The easy way is `sudo apt-get update && sudo apt-get install mysql-server`.
          • Does this means I have to Perform a re-image on the Droplet?

@rramirezm

We can run the following command to see if any additional information is provided:

sudo dpkg --configure -a

If that doesn't produce anything that's helpful, I would setup a second Droplet for testing.

Once logged in to SSH on the new Droplet, copy and paste the following multi-line command and let it run its course.

sudo apt-get update \
&& sudo apt-get -y upgrade \
&& sudo apt-get -y install build-essential mysql-server

Once the above command has completed and MySQL is installed, please run:

mysql_secure_installation

... and setup your root password (if you didn't already -- not all MySQL packages prompt you to set a root password during setup, so the above command allows you to do that).

Once MySQL is setup, install NGINX. You can do this one of two ways -- use the NGINX package that is provided by Ubuntu or add NGINX's PPA.

I prefer NGINX's PPA since it's actually maintained by them, so to install the PPA, we'd run:

sudo add-apt-repository -y ppa:nginx/stable \
&& sudo apt-get update

... and then to install NGINX:

sudo apt-get -y install nginx

At this point we should have MySQL and NGINX installed. We can now install phpMyAdmin by using:

sudo apt-get -y install phpmyadmin

When prompted to choose a web server, don't choose one (i.e. don't hit space bar to select a web server -- if you do, it'll install that web server during the process and since you're using NGINX, we don't want that). Instead, hit tab and let it run its course. When you hit tab, both of the boxes should be empty, just to confirm.

You'll then be prompted to setup phpMyAdmin. The first question it'll ask is:

Configure database for phpmyadmin with dbconfig-common?

Tab over to yes, hit enter -- then choose a password and confirm it on the next two prompts. This should complete the setup and phpMyAdmin will be located in:

/usr/share/phpmyadmin

So you then need to setup a server block that will allow you to access it, but since the installation of phpMyAdmin didn't install PHP-FPM, we should go ahead and install that since NGINX will need it to handle PHP requests:

apt-get -y install php7.0-fpm

From there, if you need help setting up your server blocks, just let me know. The above, however, should help to get you running up to the server block portion.

After running sudo dpkg --configure -a it prompted:

Setting up phpmyadmin (4:4.5.4.1-2ubuntu2) ...
/var/lib/dpkg/info/phpmyadmin.config: 44: /etc/dbconfig-common/phpmyadmin.conf: Syntax error: "(" unexpected
dpkg: error processing package phpmyadmin (--configure):
 subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
 phpmyadmin

It looks like I'll have to deploy another droplet

Have another answer? Share your knowledge.