How can I fix error during install a package with APT in Ubuntu

1

I was trying to install a package using APT and I got error:

UserName@PCname:~$ sudo apt-get install php7.2

Reading package lists... Done
Building dependency tree       
Reading state information... Done
php7.2 is already the newest version (7.2.7-1+0~20180622080852.23+jessie~1.gbpfd8e2e).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
4 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up php7.1-fpm (7.1.18-1+0~20180611145758.18+jessie~1.gbp2b32f6) ...
/var/lib/dpkg/info/php7.1-fpm.postinst: 2: /etc/apache2/envvars: =/var/run/apache2: not found
dpkg: error processing package php7.1-fpm (--configure):
 subprocess installed post-installation script returned error exit status 127
Setting up libapache2-mod-php7.2 (7.2.7-1+0~20180622080852.23+jessie~1.gbpfd8e2e) ...
/var/lib/dpkg/info/libapache2-mod-php7.2.postinst: 2: /etc/apache2/envvars: =/var/run/apache2: not found
dpkg: error processing package libapache2-mod-php7.2 (--configure):
 subprocess installed post-installation script returned error exit status 127
Setting up libapache2-mod-php7.1 (7.1.18-1+0~20180611145758.18+jessie~1.gbp2b32f6) ...
/var/lib/dpkg/info/libapache2-mod-php7.1.postinst: 2: /etc/apache2/envvars: =/var/run/apache2: not found
dpkg: error processing package libapache2-mod-php7.1 (--configure):
 subprocess installed post-installation script returned error exit status 127
dpkg: dependency problems prevent configuration of php7.2:
 php7.2 depends on libapache2-mod-php7.2 | php7.2-fpm | php7.2-cgi; however:
  Package libapache2-mod-php7.2 is not configured yet.
  Package php7.2-fpm is not installed.
  Package php7.2-cgi is not installed.

dpkg: error processing package php7.2 (--configure):
 dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                                              Errors were encountered while processing:
 php7.1-fpm
 libapache2-mod-php7.2
 libapache2-mod-php7.1
 php7.2
E: Sub-process /usr/bin/dpkg returned an error code (1)

How can I fix this?

Naziks

Posted 2018-07-03T14:07:39.207

Reputation: 65

Can you try sudo apt install --fix-broken and/or sudo apt install php7.2-fpm php7.2-cgi – Fanatique – 2018-07-03T14:11:12.690

@Fanatique - The option -f/--fix-broken belongs to apt-get, not apt (at least on Ubuntu 16.04.4). I would suggest running sudo apt-get in three successive runs with the parameters update, check and -f --reinstall install php7.2. – AFH – 2018-07-03T14:28:38.923

It doesn't works :(( – Naziks – 2018-07-05T19:59:19.970

Answers

4

This commands helps me:

1) Remove PHP and all his libraries and files

sudo apt-get purge php7.*

2) Install PHP again

sudo apt-get install php7.2

Naziks

Posted 2018-07-03T14:07:39.207

Reputation: 65

This removes all php libraries version 7.something with their configuration. I'm not sure this is the right solution for everyone here. – Joe Eifert – 2019-10-30T11:12:23.507

@JoeEifert Maybe it will be useful for someone – Naziks – 2019-12-04T07:49:06.710