LinuxCommandLibrary

phpenmod

Enable or disable PHP modules

TLDR

Enable the JSON extension for every SAPI of every PHP version

$ sudo phpenmod [json]
copy

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

SYNOPSIS

phpenmod [options] module [module...]

PARAMETERS

-s SAPI
    Specifies the PHP Server API (e.g., cli, fpm, apache2) for which the module should be enabled. If omitted, the module is enabled for all active SAPIs.

-v VERSION
    Specifies the PHP version (e.g., 7.4, 8.0) for which the module should be enabled. If omitted, the module is enabled for all active PHP versions.

-r
    Recommends enabling configuration for php-cgi instead of apache2. Less commonly used.

-h
    Displays a help message and exits.

module
    The name of the PHP module or extension to enable (e.g., mysqli, gd, intl). Multiple modules can be specified.

DESCRIPTION

phpenmod is a utility command used primarily on Debian-based Linux distributions to enable PHP modules or extensions for various PHP versions and Server API (SAPI) configurations. It simplifies the process of managing PHP settings by creating symbolic links from the mods-available directory (where module .ini files are stored) to the conf.d directories of specific PHP versions and SAPIs (e.g., cli, fpm, apache2). This ensures that the chosen module is loaded when PHP processes for those SAPIs are started.

It centralizes PHP module management, preventing the need to manually edit multiple .ini files. After using phpenmod, a restart of the web server (like Apache or Nginx with PHP-FPM) or PHP-FPM service is usually required for the changes to take effect. This command requires root privileges to execute.

CAVEATS

This command is primarily available and used on Debian/Ubuntu and their derivative distributions. It requires root (sudo) privileges to modify system-wide PHP configurations. Enabling a module only creates configuration links; a restart of the associated web server (e.g., Apache, Nginx) or PHP-FPM service is necessary for the changes to become active.

COMMON USAGE

To enable the gd module for PHP 8.1 FPM: sudo phpenmod -v 8.1 -s fpm gd
To enable mysqli for all PHP versions and SAPIs: sudo phpenmod mysqli

CONFIGURATION FILES

Enabled modules create symlinks in directories like /etc/php/<version>/<sapi>/conf.d/ pointing to actual .ini files located in /etc/php/<version>/mods-available/.

HISTORY

phpenmod is part of the php-common package, which was introduced in Debian/Ubuntu to standardize and simplify the management of PHP configurations across different PHP versions and SAPIs. Its development is tied to the evolution of PHP packaging within these distributions, aiming to provide a consistent and easy-to-use interface for administrators.

SEE ALSO

Copied to clipboard