APT - HowTo's

mail

How to reinstall some package configuration files ?

Situation

I've installed PHP-FPM, edited configuration files without making backups first () and now things have broken bad, I'd like to revert to a cleaner situation.

Solution

  1. get the exact package name :
    dpkg -l | awk '/fpm/ {print $1" "$2}'
    ii php-fpm
    ii php8.1-fpm
  2. list its configuration files :
    dpkg --status php8.1-fpm
    
    Conffiles:
     /etc/apache2/conf-available/php8.1-fpm.conf b1e43a02b16bef4f689f6a32eaf8c3a9
     /etc/init.d/php8.1-fpm 40246d5e9590bae90b133167b9bfc118
     /etc/logrotate.d/php8.1-fpm 4bbd87237b3b0883169be0d7f856aad4
     /etc/php/8.1/fpm/php-fpm.conf 75494c14cd7739481ba87d225e031b49
     /etc/php/8.1/fpm/pool.d/www.conf 0e7522a4780a6e196ba34653d7f18ada
    
  3. remove / disable those you want to reinstall :
    mv /etc/php/8.1/fpm/php-fpm.conf{,_DELETEME}
    mv /etc/php/8.1/fpm/pool.d/www.conf{,_DELETEME}
  4. (re)install the package's missing files :
    apt install --reinstall -o Dpkg::Options::="--force-confmiss" php8.1-fpm
mail

How to restore a file to its fresh install state ?

Situation

I've installed PHP and made changes to /etc/php/8.1/cgi/php.ini without making a backup first . Now, I'd like to recover it to its initial state.

Solution

  1. retrieve the name of the package that created php.ini :
    dpkg -S php.ini
    php8.1-common: /usr/lib/php/8.1/php.ini-production
    php8.1-common: /usr/lib/php/8.1/php.ini-development
    php8.1-common: /usr/lib/php/8.1/php.ini-production.cli
    answer : php8.1-common
  2. check it by listing the package contents :
    dpkg -L php8.1-common | grep php.ini
    /usr/lib/php/8.1/php.ini-development
    /usr/lib/php/8.1/php.ini-production
    /usr/lib/php/8.1/php.ini-production.cli
  3. in this specific case, /etc/php/8.1/cgi/php.ini was copied from /usr/lib/php/8.1/php.ini-production.cli. View differences between files :
    diff /usr/lib/php/8.1/php.ini-production.cli /etc/php/8.1/cgi/php.ini
    503c503
    < display_errors = Off
    ---
    > display_errors = On
    846c846
    < ;upload_tmp_dir =
    ---
    > upload_tmp_dir = /path/to/some/dir
  4. so, I can either
    • undo changes manually
      I've simplified the changes made to /etc/php/8.1/cgi/php.ini for this article, things are never that simple in real life .
    • overwrite the file I changed :
      cp /usr/lib/php/8.1/php.ini-production.cli /etc/php/8.1/cgi/php.ini
mail

How to configure a proxy for apt ?

This defines a proxy for apt only. If you want to declare system-wide proxy settings, read this.
mail

How to prevent a package from being updated ? hold it !

Usage

If you want to freeze a given package in its current state and forbid it to be installed, updated or removed, you can hold it.

Example

hold the package packageName :

apt-mark hold packageName

list packages currently on hold :

un-hold the package packageName :

apt-mark unhold packageName