How to Enable or Disable PHP Modules on Ubuntu 20.04 | 18.04

Enable or Disable PHP Modules

In this guide, we will be showing how you can enable or disable PHP modules on Ubuntu 20.04 LTS as well as other versions.

PHP modules are extensions that add features to the core PHP functions.

Prerequisites

In this guide, we will be making the assumption that you have already installed a supported PHP version such as PHP 7.4 or PHP 8.0 on your Ubuntu system. This short tutorial will show you how to install PHP modules on your system.

Managing PHP Modules

The php-common package provides the following commands to manage PHP modules as listed below:

  • phpenmod: Used to enable modules in PHP
  • phpdismod: Used to disable modules in PHP
  • phpquery: Used to view status of modules of PHP

Modules can be enabled or disabled in PHP for a specific SAPI (Server API). The three common ones found on any Ubuntu system are CLI, FPM, and Apache2. You can use the -s switch to enable or disable modules in PHP for any of these.

Enable PHP Modules

To enable a specific module in PHP you need to use phpenmod command followed by module name using the following syntax.

Read Also  SenchaCon 2016 Announced for November

$ phpenmod MODULE_NAME

Here is an example showing how to enable curl module for ALL PHP versions and all SAPI.

$ phpenmod curl

phpenmod provides a -v switch to specify the PHP version that you intend to enable the module for with the following syntax.

$ phpenmod -v PHP_VERSION MODULE_NAME

This example shows how to enable curl module for specific PHP versions.

Enable module for specific php version

$ phpenmod -v 7.3 curl
$ phpenmod -v 7.4 curl

Moving further, this is the syntax if you need to specify the SAPI using the -s switch.

$ phpenmod -s SAPI MODULE_NAME

Now let’s enable curl for all the SAPIs individually.

$ phpenmod -s cli curl
$ phpenmod -s fpm curl
$ phpenmod -s apache2 curl

Disable PHP Modules

You can use phpdismod to disable any unused or unwanted PHP modules from your system. Here we will disable the curl module for ALL PHP versions and all SAPI.

$ phpdismod curl

The following command will disable the specific module for the specified version:

$ phpdismod -v 7.4 curl

The following example will disable the module only for the specified SAPI

$ phpdismod -s apache2 curl

Conclusion

You should now be able to enable and disable PHP modules based on PHP version and SAPI to keep your system running optimally.