Skip to main content

Installing PHP Extensions on Ubuntu and Debian

PHP · 19.04.2026 · 4 min read
Illustration for “Installing PHP Extensions on Ubuntu and Debian”

PHP Extension Types

PHP extensions expand what the language can do: they add support for databases, images, cryptography and network protocols. There are two types: built-in (bundled with PHP) and PECL extensions (installed separately via pecl or apt).

Listing Installed Extensions

# List all loaded extensions
php -m

# Check a specific extension
php -m | grep curl

# Detailed information
php --ri gd

Installing Extensions via apt

# Update the package list
sudo apt update

# Install the extensions for PHP 8.2
sudo apt install php8.2-curl php8.2-gd php8.2-mbstring php8.2-xml \
    php8.2-zip php8.2-mysql php8.2-pgsql php8.2-redis \
    php8.2-imagick php8.2-intl php8.2-bcmath php8.2-soap

# Restart PHP-FPM
sudo systemctl restart php8.2-fpm
CMS / FrameworkRequired extensions
WordPresscurl, gd, mbstring, mysql, xml, zip, intl
Laravelbcmath, ctype, curl, dom, fileinfo, json, mbstring, openssl, pdo, tokenizer, xml
Drupalgd, pdo, xml, json, mbstring, dom, hash
Magento 2bcmath, curl, gd, intl, mbstring, pdo_mysql, soap, xsl, zip

Installing PECL Extensions (Redis, Imagick)

# Redis via apt (recommended)
sudo apt install php8.2-redis

# Imagick
sudo apt install php8.2-imagick

# Via PECL (if it is not in apt)
sudo pecl install redis
echo "extension=redis.so" | sudo tee /etc/php/8.2/mods-available/redis.ini
sudo phpenmod redis

Managing Extensions: phpenmod / phpdismod

# Enable an extension
sudo phpenmod -s fpm mbstring

# Disable an extension
sudo phpdismod -s fpm xdebug

# Apply the changes
sudo systemctl reload php8.2-fpm
To cover several PHP versions at once, name the version you need: sudo apt install php7.4-curl php8.1-curl php8.2-curl — each extension is installed independently for each PHP version.

Compiling an Extension from Source

sudo apt install php8.2-dev
pecl download xdebug
tar xf xdebug-*.tgz && cd xdebug-*
phpize && ./configure --with-php-config=/usr/bin/php-config8.2
make && sudo make install

Common Errors Without the Right Extension

Call to undefined function

PHP Fatal error:  Uncaught Error: Call to undefined function curl_init() in /var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php:1

This means the curl extension is either not installed at all, or installed but not enabled for the SAPI that is actually serving the request. CLI and FPM for the same PHP version use separate conf.d directories, and their module lists can differ.

could not find driver (PDO)

PDOException: could not find driver in /var/www/html/app/Database.php:14

A common beginner mistake: the pdo extension is installed, but the specific driver — pdo_mysql or pdo_pgsql — is not. Those are two separate apt packages.

Class "Imagick" not found

Fatal error: Uncaught Error: Class "Imagick" not found in /var/www/html/app/Thumbnail.php:9

The PECL extension is installed but not activated, or it is activated for only one of the SAPIs.

When Installing via apt Is Not Enough

  • An extension is enabled for CLI but not for FPM (or the other way around) — module management is separate: phpenmod -s fpm curl and phpenmod -s cli curl are different commands.
  • After apt install php8.2-imagick, FPM was not restarted — the module only loads into a process's memory when it starts, and a plain Nginx reload is not enough.
  • The extension build from the ondrej/php repository has not been released for the very latest PHP version yet — the choice is either waiting for the package update or compiling from source.
  • The site uses several PHP versions at once — the extension needs to be installed for each version separately, apt does not do that automatically.

Verifying the Result

# Does the interpreter see the extension at all?
php -m | grep -i curl

# An explicit check from code is more reliable than grep
php -r "var_dump(extension_loaded('curl'));"

# The same, but for PHP-FPM: create an info.php with phpinfo()
# and look for the extension section in the browser output — the
# module list shown there for CLI and FPM can differ

If php -m shows the module but the code still fails with "Call to undefined function", you almost certainly checked CLI while the error comes from FPM (or the reverse).

Another source of confusion: extensions built manually from source do not land in /etc/php/8.2/mods-available/, but wherever the build pointed them, and phpenmod knows nothing about them. Such modules must be wired up by hand with an extension= directive in a separate ini file, and enabled for the right SAPI config manually, without apt's automation.

After a system update via apt upgrade, modules built from source do not get updated along with the packaged PHP — when moving to a new minor version they will need to be rebuilt, or after restarting FPM you will get an error about an incompatible module API version.

Was this article helpful?
← Back to Knowledge Base Ask Support