How to uninstall PHP 7 completely? (Kali Linux/Debian)

How to uninstall PHP 7 completely? (Kali Linux/Debian)

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

How to uninstall PHP 7 completely on Kali Linux and Debian

When managing a development environment on Kali Linux or standard Debian, the default PHP package often becomes an obstacle. In older distributions like Kali 2016.2, PHP 7 was pre-installed alongside legacy versions. If your workflow requires PHP 5.6 specifically—perhaps for compatibility with existing codebases—you cannot simply downgrade the version; you must remove the newer package entirely to prevent dependency conflicts.

The danger of attempting a naive uninstallation on Kali or Debian lies in the package manager's strict dependency resolution. Unlike Arch Linux, which uses an AUR helper approach often more forgiving of partial removals, Debian-based systems treat dependencies as critical. If you attempt to force-remove PHP 7 without addressing its associated libraries and extensions, apt will refuse to proceed or, worse, break your system by removing unrelated packages required for the OS to function.

The Danger of Force Removal

A common pitfall when trying to uninstall a specific PHP version is using the -f (force) flag with apt-get remove. This command bypasses dependency checks, telling the package manager to delete the files regardless of what else depends on them. While this might seem like a quick fix, it leaves orphaned libraries in your system directories.

For example, simply running:

sudo apt-get remove php7.0

will strip the main interpreter but often leaves behind php-common, libapache2-mod-php7.0, and various extension modules. These remnants confuse the package manager because they still reference the removed version in their metadata. If you subsequently try to install PHP 5.6, apt may fail because it detects that dependencies for other system tools are now pointing to a missing library version.

Purging Dependencies Correctly

To uninstall PHP 7 completely without breaking your Kali installation, you must purge both the package and its configuration files, then allow the package manager to resolve the remaining dependency graph. The safest approach involves identifying all packages that depend on PHP 7 before removing them.

Run the following command to list dependencies associated with the PHP 7 stack:

sudo apt-cache depends php7.0

This output will reveal which libraries and modules are tied to PHP 7. You need to ensure these are handled correctly before removal. If apt complains about broken packages after a standard remove, it is because those dependencies have become "half-removed."

The robust method involves purging the main package and then asking apt to fix any resulting breakage:

sudo apt-get purge php7.0*
sudo apt-get autoremove
sudo apt-get -f install

The -f install flag is crucial here; it tells the package manager to attempt to reinstall missing dependencies that are required by other essential system packages, effectively cleaning up the mess left behind by an incomplete removal. This step ensures that your base system remains intact and ready for the next installation.

Installing PHP 5.6 Safely

Once PHP 7 is fully purged and your system's dependency graph is clean, you can proceed to install PHP 5.6. On Kali Linux or Debian, older versions are usually available in the main repositories if you haven't recently upgraded them to a version where PHP 7 is the only option (such as recent Debian Bullseye or newer).

If your current repository only contains PHP 7.x and you specifically need PHP 5.6, you will likely need to add an archive repository containing older packages. This introduces a security trade-off: you gain the specific version required for your legacy projects but lose automatic security updates for that specific PHP binary until you upgrade again.

Add the appropriate repository source, update your package list, and install:

sudo apt-get update
sudo apt-get install php5.6

After installation, verify which version is active using php -v. Note that on Debian systems, switching PHP versions often requires updating the web server configuration (e.g., changing LoadModule directives in Apache or PHP-FPM pool files) to match the new binary path and shared object locations.

Why This Approach Matters

The core lesson here is respecting the package manager's dependency graph. On Debian and Kali, "completely" uninstalling a major component like PHP isn't just about deleting an executable; it's about reconciling the entire ecosystem of libraries that rely on it. By avoiding force removal and utilizing autoremove and -f install, you maintain system integrity while achieving your goal of running PHP 5.6. This method prevents the scenario where a simple version switch results in a non-bootable or unstable development environment.

Our network