Question

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

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)

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

@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

sudo mv /var/lib/dpkg/info/phpmyadmin.* /tmp/ sudo dpkg --remove --force-remove-reinstreq phpmyadmin sudo apt remove phpmyadmin sudo apt autoremove sudo apt autoclean

thanks me later!!!

So whenever anyone wants to remove phpmyadmin and apache just first of all stop all running services using below commands… stop apache2

sudo systemctl stop apache2.service

prevent apache2 to start at boot

sudo systemctl disable apache2.service

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

@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.