LinuxCommandLibrary

phpdismod

Disable specific PHP modules

TLDR

Disable the JSON extension for every SAPI of every PHP version

$ sudo phpdismod [json]
copy

Disable the JSON extension for PHP 7.3 with the cli SAPI
$ sudo phpdismod -v [7.3] -s [cli] [json]
copy

SYNOPSIS

phpdismod [options] <module> [<module>...]

PARAMETERS

<module> [<module>...]
    One or more names of the PHP modules to be disabled (e.g., xdebug, opcache).

-v <version>, --version <version>
    Specifies the PHP version for which the module should be disabled (e.g., 7.4, 8.1). Use ALL to affect all installed PHP versions.

-s <sapi_name>, --sapi <sapi_name>
    Specifies the SAPI (Server API) name for which the module should be disabled (e.g., apache2, cli, fpm). Use ALL to affect all configured SAPIs for the specified version.

-h, --help
    Displays a brief help message and exits.

-q, --quiet
    Suppresses output messages during execution.

DESCRIPTION

The phpdismod command is a utility primarily found on Debian-based Linux distributions, part of the php-common package. It is used to disable PHP modules for one or more specific Server API (SAPI) configurations. This command acts as the counterpart to phpenmod, which is used to enable modules.

When a PHP module is installed, its configuration file (e.g., opcache.ini) is typically placed in a mods-available directory for each PHP version and SAPI. phpdismod works by removing the symbolic link from the conf.d directory (where PHP reads its active configurations) back to the mods-available directory, effectively disabling the module for the specified SAPI.

This tool simplifies PHP module management, especially in environments with multiple PHP versions or different SAPIs (like Apache, CLI, or FPM), by automating the process of enabling or disabling extensions without manual symlink manipulation. It requires superuser privileges to operate.

CAVEATS

  • Permissions: phpdismod requires root or superuser privileges to modify system configuration files. Use with sudo.
  • Server Reload: After disabling a module, a web server (e.g., Apache, Nginx) or PHP-FPM service restart/reload is typically required for changes to take effect in the respective SAPI environments. CLI changes are immediate.
  • Module Availability: The module configuration file must exist in the mods-available directory for phpdismod to manage it. If the module is not installed, the command cannot disable it.
  • 'ALL' Usage: Using ALL with -v or -s affects all relevant versions or SAPIs. Exercise caution to avoid unintended widespread changes.

WORKING MECHANISM

phpdismod operates by managing symbolic links. For each PHP version and SAPI, module configuration files (e.g., opcache.ini) are stored in /etc/php/<version>/mods-available/. When a module is enabled by phpenmod, a symbolic link is created in the SAPI-specific configuration directory (e.g., /etc/php/<version>/apache2/conf.d/). phpdismod's primary function is to remove this symbolic link, thus preventing PHP from loading the module for that specific SAPI, effectively disabling it.

IMPACT ON APPLICATIONS

Disabling a PHP module can impact web applications or CLI scripts that rely on its functionality. For instance, disabling mysqli would prevent PHP scripts from connecting to MySQL databases using that extension, potentially causing application errors. Always ensure that the modules you disable are not critical for your running applications or services.

HISTORY

phpdismod emerged as part of the php-common package within Debian and Ubuntu's PHP ecosystem. Its development aimed to standardize and simplify the process of managing PHP extensions across various PHP versions and Server APIs (SAPIs) without requiring manual manipulation of symbolic links or `.ini` files. It became an essential tool for system administrators and developers to toggle PHP modules efficiently, streamlining configuration management since its introduction alongside phpenmod.

SEE ALSO

phpenmod(1), php(1), systemctl(1), apache2ctl(8)

Copied to clipboard