GoAdmio

removephp

Uninstall a PHP version (such as 8.3) with its extensions, PHP-FPM service, configuration, and socket folder, and refuse to remove PHP 8.5 unless --force is given

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/removephp removes one installed PHP version from the server, the opposite of installphp. It:

It works on AlmaLinux, Rocky, CentOS, Red Hat, Fedora, Debian, and Ubuntu.

[!WARNING] removephp does not check whether any hosting account uses the version, or whether it is the server's default PHP version. Accounts still using it will stop working. Move them to another version first with multiphp, and change the default with defaultphp if needed.


Quick start

# Remove PHP 8.2
/go/removephp 8.2

Syntax

/go/removephp <version> [--force] [--progress]
Form Behavior
/go/removephp <version> Removes that PHP version.
/go/removephp 8.5 --force Removes PHP 8.5. Without --force, PHP 8.5 is refused.
/go/removephp <version> --progress Also prints 100 when finished, for GoAdmio's progress display.

The version must be the first argument. /go/removephp --force 8.5 fails with Invalid PHP Version.

Run the command as root, or with sudo. A few steps run without sudo inside the script.


Options

Argument Required Default Notes
<version> Yes — One digit, a dot, and one digit, for example 8.3.
--force No — Allows removing PHP 8.5. It is the only check it skips.
--progress No — Reports completion for GoAdmio's progress display.

Both flags are detected anywhere in the arguments, after the version.


Output

Outcome What you get
No version given Usage: removephp <Version> and exit status 1.
Version in the wrong format Invalid PHP Version and exit status 1.
PHP 8.5 without --force PHP 8.5 Required and exit status 1.
Another install or removal is running Instance (<name>) already running. and exit status 1.
Removal ran The output of dnf or apt, plus step names such as Removing PHP 8.3 FPM.
Removal ran with --progress The last step reports Removing PHP <version> completed successfully, then 100 is printed.

Notes on the output:


Examples

# Remove PHP 8.2
/go/removephp 8.2
# Remove PHP 8.5, which is normally protected
/go/removephp 8.5 --force
# Check that it's gone
rpm -qa | grep php81          # AlmaLinux, Rocky, CentOS, Red Hat, Fedora
dpkg -l | grep php8.1         # Debian, Ubuntu

Before removing a version, move every account that uses it to another version with multiphp. That page also shows how to list the installed PHP versions.


Troubleshooting

Symptom Likely cause Fix
Instance (installphp) already running. An install or removal started within the last 10 minutes holds the lock. Wait and try again. If nothing is running, the lock is ignored after 10 minutes.
Usage: removephp <Version> No argument. Pass a version such as 8.2.
Invalid PHP Version The version isn't in the form 8.2, or a flag came first. Put the version first.
PHP 8.5 Required GoAdmio treats 8.5 as required. Only if you are sure, add --force.
Sites return 502/503 after the removal Accounts still used that version. Move them with multiphp.
Lots of No match or Unable to locate package lines The extension list includes packages that don't exist for that version. Ignore them. The final wildcard step removes whatever remains.
The command finished but PHP packages remain Exit status is always 0, and errors are not checked. Check with rpm -qa or dpkg -l, then remove leftovers manually.
Debian/Ubuntu: libapache2-mod-php<version> is still installed The Apache module line repeats apt -y remove and fails. Run apt remove libapache2-mod-php<version> yourself.
Debian/Ubuntu: Apache still has a PHP-FPM config for the removed version The script runs a2enconf (enable) where it probably should run a2disconf (disable). Check /etc/apache2/conf-enabled/, and run a2disconf php<version>-fpm if needed.
RHEL family: errors such as PROGRESSBAR: command not found near the INTL step The INTL lines are written in upper case, so they don't run. Harmless. The final wildcard step removes the INTL package.
Custom php.ini settings are gone after reinstalling The version's whole config folder is deleted. Re-apply settings with commands such as postmaxsize and memorylimit.

Details

What happens on each run

flowchart TD
    A["removephp version"] --> B["Log the call, load /go/function"]
    B --> C{"Lock held in the last 10 minutes?"}
    C -- "Yes" --> X1["Print: Instance already running, exit 1"]
    C -- "No" --> D["Take the lock"]
    D --> E{"Valid version?"}
    E -- "No" --> X2["Usage or Invalid PHP Version, exit 1"]
    E -- "Yes" --> F{"8.5 without --force?"}
    F -- "Yes" --> X3["PHP 8.5 Required, exit 1"]
    F -- "No" --> G{"OS family"}
    G -- "RHEL family" --> H["dnf remove each package, then php83-*"]
    G -- "Debian or Ubuntu" --> I["apt remove each package, then php8.3-*"]
    H --> J["Delete config and data folders"]
    I --> J
    J --> K["Delete /run/sock/83"]
    K --> L["Release the lock"]

The lock

removephp uses the same lock file as installphp: /usr/local/goadmio/lock/installphp.lock. The file holds the name of the command that created it. A lock younger than 10 minutes blocks the command. An older lock is treated as stale and replaced. The lock is removed when the command exits, however it exits.

What is removed

OS family Packages Folders deleted
AlmaLinux, Rocky, CentOS, Red Hat, Fedora php83, php83-php-fpm, and about forty extension packages, then php83-* /etc/opt/remi/php83, /var/lib/php83, /run/sock/83
Debian, Ubuntu php8.3, php8.3-fpm, and about forty extension packages, then php8.3-* /etc/php/8.3, /run/sock/83

The examples use PHP 8.3. On Debian and Ubuntu, apt remove is used, not purge, and no autoremove is run, so unused dependencies stay installed.

What is not changed

Time

The command removes about forty packages one at a time, so it can take several minutes.


See also

Command Description
installphp Install a PHP version with its extensions and PHP-FPM service
multiphp Change the PHP version of one domain or all domains, or list the installed PHP versions
defaultphp Show or change the server's default PHP version
listphp List the PHP versions available to install from the server's package repositories
extension List, install, or remove a PHP extension across every installed PHP version
fpm Restart all installed PHP-FPM versions