Most PHP applications need extensions beyond the core: database drivers, image libraries, internationalisation, caching. On Linux they’re installed as packages and enabled per PHP version and SAPI. Here’s how to install them, check them, and troubleshoot “Class not found” or “extension missing” errors.
Install with apt (Debian/Ubuntu)
Packages are named php<version>-<extension>, or php-<extension> for the distribution’s default version:
sudo apt install -y php8.3-mysql php8.3-curl php8.3-gd php8.3-mbstring \
php8.3-xml php8.3-zip php8.3-intl php8.3-bcmath php8.3-imagick php8.3-redis
sudo systemctl restart php8.3-fpm
If you run several PHP versions, install the extension for each one. See PHP versions on Ubuntu.
Find available packages:
apt search php8.3- | grep -i redis
Install with dnf (AlmaLinux/Rocky/RHEL)
sudo dnf install -y php-mysqlnd php-gd php-mbstring php-xml php-intl php-zip php-pecl-redis5
sudo systemctl restart php-fpm
Package names differ slightly (php-mysqlnd, php-pecl-*). Remi’s repository provides more versions and extensions.
Common extensions and who needs them
| Extension | Used for |
|---|---|
mysql (mysqli, pdo_mysql) |
MySQL/MariaDB — WordPress, Laravel, most apps |
pgsql |
PostgreSQL |
curl |
HTTP requests to APIs |
mbstring |
Multibyte (UTF-8) strings — required by many frameworks |
xml (dom, simplexml, xmlwriter) |
XML, feeds, many libraries |
zip |
Archives, plugin/theme uploads, Composer |
gd or imagick |
Image resizing, thumbnails |
intl |
Locales, formatting, sorting — Laravel, Symfony, Nextcloud |
bcmath / gmp |
Arbitrary precision math — payments, crypto libraries |
redis / memcached |
Object caching, sessions |
opcache |
Bytecode cache (usually enabled by default) |
soap |
SOAP APIs |
sodium |
Modern cryptography (built in since PHP 7.2) |
exif |
Image metadata (orientation) |
Applications usually document their requirements; WordPress lists “recommended” modules in Tools → Site Health.
Enable and disable
Debian/Ubuntu manage extensions with phpenmod/phpdismod, which create symlinks in each SAPI’s conf.d directory:
sudo phpenmod -v 8.3 redis
sudo phpdismod -v 8.3 -s cli xdebug # disable only for the CLI
sudo systemctl restart php8.3-fpm
Settings for an extension live in /etc/php/8.3/mods-available/<ext>.ini.
Check what’s loaded
php -m # CLI modules
php -m | grep -i redis
php --ri redis # details of one extension
php8.3 -m # a specific version
The CLI and FPM can differ. To see what the web PHP loads, use a temporary phpinfo page or your app’s system report.
PECL extensions
Extensions not packaged for your distribution can be built with PECL:
sudo apt install -y php8.3-dev php-pear build-essential
sudo pecl install mongodb
echo "extension=mongodb.so" | sudo tee /etc/php/8.3/mods-available/mongodb.ini
sudo phpenmod -v 8.3 mongodb
sudo systemctl restart php8.3-fpm
Prefer distribution or Surý packages when available — they’re updated automatically with security fixes; PECL builds must be rebuilt by hand after PHP upgrades. (PECL is gradually being superseded by the newer PIE installer.)
In Docker images
The official php image uses helper scripts:
FROM php:8.3-fpm
RUN apt-get update && apt-get install -y libzip-dev libicu-dev libpng-dev \
&& docker-php-ext-install pdo_mysql zip intl gd opcache \
&& pecl install redis && docker-php-ext-enable redis \
&& rm -rf /var/lib/apt/lists/*
The community install-php-extensions script simplifies this further by resolving system dependencies automatically.
Troubleshooting
Call to undefined function mysqli_connect()/Class "PDO" not found— database extension missing for the SAPI in use; install and restart PHP-FPM.- Installed but not loaded — wrong PHP version’s package, or PHP-FPM not restarted.
PHP Warning: Module "redis" is already loaded— enabled twice (duplicate.inifiles inconf.d).- Composer: “requires ext-intl” — install the extension for the CLI version Composer runs with.
Related: installing PHP and MySQL and php.ini settings.