0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

php-fpm をアンインストールするときは apt remove だけじゃなくて apt autoremove しよう

Last updated at Posted at 2025-10-10

概要

php8.1-fpm をインストールしたかったが、php-fpm を間違えてインストールした。

php-fpm を削除しようとしたら、php-fpm は削除できたが、インストールした時にいっしょにインストールされたパッケージが残っていた。

結論としては、sudo apt remove php-fpm --purge するだけではなく、このコマンドの実行結果のメッセージにある通り、sudo apt autoremove --purge を実行する必要があった。

前提

  • php8.1-fpm は ppa ( ondrej/php) でインストール済み
  • Ubuntu 24.04環境

詳細

.bash
# 間違えてインストールした
sudo apt install -y php-fpm
......
The following additional packages will be installed:
  php-common php8.3-cli php8.3-common php8.3-fpm php8.3-opcache php8.3-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  php-common php-fpm php8.3-cli php8.3-common php8.3-fpm php8.3-opcache php8.3-readline
0 upgraded, 7 newly installed, 0 to remove and 137 not upgraded.
Need to get 4,983 kB of archives.
After this operation, 22.5 MB of additional disk space will be used.

php-fpm パッケージだけを削除したため、いっしょにインストールされていた他の php8.3関連のパッケージが残ってしまう:

.bash
# 間違えてphp-fpm パッケージだけを削除
sudo apt remove php-fpm --purge
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  php-common php8.3-cli php8.3-common php8.3-fpm php8.3-opcache php8.3-readline
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  php-fpm*
0 upgraded, 0 newly installed, 1 to remove and 137 not upgraded.
After this operation, 11.3 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 200639 files and directories currently installed.)
Removing php-fpm (2:8.3+93ubuntu2) ...

# 依存パッケージの一覧を更新
sudo apt update

# sudo apt autoremove しないと、php-common が残っている
sudo dpkg -l php* | grep '^ii'
ii  php-common         2:93ubuntu2            all          Common files for PHP packages

# sudo apt autoremove しないと、php8.3-fpm も残っている
dpkg -l php*-fpm | grep '^ii'
ii  php8.1-fpm     8.1.33-1+ubuntu24.04.1+deb.sury.org+1 amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php8.3-fpm     8.3.6-0ubuntu0.24.04.5                amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)

# sudo apt autoremove しないと、
# php関連のパッケージ ( php8.3-cli とか) も削除されていない
sudo dpkg -l php* | grep '^ii'
ii  php-common       2:96+ubuntu24.04.1+deb.sury.org+1     all          Common files for PHP packages
ii  php8.1-cli       8.1.33-1+ubuntu24.04.1+deb.sury.org+1 amd64        command-line interpreter for the PHP scripting language
ii  php8.1-common    8.1.33-1+ubuntu24.04.1+deb.sury.org+1 amd64        documentation, examples and common module for PHP
ii  php8.1-fpm       8.1.33-1+ubuntu24.04.1+deb.sury.org+1 amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php8.1-opcache   8.1.33-1+ubuntu24.04.1+deb.sury.org+1 amd64        Zend OpCache module for PHP
ii  php8.1-readline  8.1.33-1+ubuntu24.04.1+deb.sury.org+1 amd64        readline module for PHP
ii  php8.3-cli       8.3.6-0ubuntu0.24.04.5                amd64        command-line interpreter for the PHP scripting language
ii  php8.3-common    8.3.6-0ubuntu0.24.04.5                amd64        documentation, examples and common module for PHP
ii  php8.3-fpm       8.3.6-0ubuntu0.24.04.5                amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php8.3-opcache   8.3.6-0ubuntu0.24.04.5                amd64        Zend OpCache module for PHP
ii  php8.3-readline  8.3.6-0ubuntu0.24.04.5                amd64        readline module for PHP

個々のパッケージを明示的に apt remove で アンインストール: ※ 推奨は apt autoremove で一括で削除

.bash
sudo apt remove --purge php8.3-cli php8.3-common php8.3-fpm php8.3-opcache php8.3-readline
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  php8.3-cli* php8.3-common* php8.3-fpm* php8.3-opcache* php8.3-readline*
0 upgraded, 0 newly installed, 5 to remove and 138 not upgraded.
After this operation, 22.5 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 200751 files and directories currently installed.)
Removing php8.3-fpm (8.3.6-0ubuntu0.24.04.5) ...
Removing php8.3-cli (8.3.6-0ubuntu0.24.04.5) ...
update-alternatives: using /usr/bin/php8.1 to provide /usr/bin/php (php) in auto mode
update-alternatives: using /usr/bin/phar8.1 to provide /usr/bin/phar (phar) in auto mode
update-alternatives: using /usr/bin/phar.phar8.1 to provide /usr/bin/phar.phar (phar.phar) in auto mode
Removing php8.3-readline (8.3.6-0ubuntu0.24.04.5) ...
Removing php8.3-opcache (8.3.6-0ubuntu0.24.04.5) ...
Removing php8.3-common (8.3.6-0ubuntu0.24.04.5) ...
Processing triggers for man-db (2.12.0-4build2) ...
(Reading database ... 200648 files and directories currently installed.)
Purging configuration files for php8.3-fpm (8.3.6-0ubuntu0.24.04.5) ...
Purging configuration files for php8.3-common (8.3.6-0ubuntu0.24.04.5) ...
dpkg: warning: while removing php8.3-common, directory '/etc/php/8.3/mods-available' not empty so not removed
Purging configuration files for php8.3-cli (8.3.6-0ubuntu0.24.04.5) ...
dpkg: warning: while removing php8.3-cli, directory '/etc/php/8.3' not empty so not removed
Purging configuration files for php8.3-readline (8.3.6-0ubuntu0.24.04.5) ...
Purging configuration files for php8.3-opcache (8.3.6-0ubuntu0.24.04.5) ...

# 無事削除されている
sudo dpkg -l php* | grep '^ii'
ii  php-common       2:96+ubuntu24.04.1+deb.sury.org+1     all          Common files for PHP packages
ii  php8.1-cli       8.1.33-1+ubuntu24.04.1+deb.sury.org+1 amd64        command-line interpreter for the PHP scripting language
ii  php8.1-common    8.1.33-1+ubuntu24.04.1+deb.sury.org+1 amd64        documentation, examples and common module for PHP
ii  php8.1-fpm       8.1.33-1+ubuntu24.04.1+deb.sury.org+1 amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php8.1-opcache   8.1.33-1+ubuntu24.04.1+deb.sury.org+1 amd64        Zend OpCache module for PHP
ii  php8.1-readline  8.1.33-1+ubuntu24.04.1+deb.sury.org+1 amd64        readline module for PHP

明示的に個々にアンインストールしたパッケージに漏れがないことを確認 ( 推奨は apt autoremove で一括で削除) :

.bash
# これ以上何も削除するものはない ( = apt remove で漏れなく削除した)
sudo apt autoremove --purge
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 138 not upgraded.    # 何も削除されていない
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?