Websites & apps

Install and enable PHP extensions on a Linux VPS

Find which PHP extensions are loaded, install missing ones from packages or PECL for the right PHP version, enable them for PHP-FPM and the CLI, and verify.

IntermediateLinux VPS3 min read

Errors such as Call to undefined function imagecreatefromjpeg() or Class "IntlDateFormatter" not found mean a PHP extension is missing. On a VPS you install extensions yourself, and the main trap is installing them for the wrong PHP version. This guide covers Ubuntu/Debian and AlmaLinux/Rocky.

Before you start

  • Root or sudo access.
  • Know which PHP version your site uses. The CLI and the web server can differ: compare php -v with a phpinfo() page or your PHP-FPM service name.

See which extensions are loaded

php -m

For a specific version on servers with several: php8.3 -m. Check one extension:

php -m | grep -i intl

The web server's PHP may load different files than the CLI; phpinfo() shows the truth for websites (delete the file afterwards).

Install on Ubuntu and Debian

Packages are named php<version>-<extension>:

apt install php8.3-intl php8.3-gd php8.3-mbstring php8.3-zip php8.3-curl php8.3-xml php8.3-bcmath

Popular PECL extensions are packaged too: php8.3-redis, php8.3-imagick, php8.3-apcu. Search with apt search php8.3- | less. Newer PHP versions come from the ondrej/php PPA (Ubuntu) or packages.sury.org (Debian).

Extensions are enabled automatically. Toggle them with:

phpenmod -v 8.3 intl
phpdismod -v 8.3 xdebug

Install on AlmaLinux and Rocky

With the default AppStream PHP:

dnf install php-intl php-gd php-mbstring php-zip php-xml php-bcmath php-pecl-zip

With Remi's repository and versioned collections:

dnf install php83-php-intl php83-php-pecl-redis5

Remi builds have their own config folder (/etc/opt/remi/php83/php.d/) and service (php83-php-fpm).

Build an extension with PECL

Only if no package exists:

apt install php8.3-dev php-pear build-essential
pecl -d php_suffix=8.3 install mongodb

Then enable it by creating an ini file, e.g. /etc/php/8.3/mods-available/mongodb.ini with extension=mongodb.so, and run phpenmod -v 8.3 mongodb. PECL builds must be rebuilt after major PHP upgrades.

Restart PHP and verify

systemctl restart php8.3-fpm

Use php-fpm on AlmaLinux, or restart Apache if PHP runs as an Apache module. Verify:

php8.3 -m | grep -iE 'intl|gd|redis'

Then reload your site or phpinfo() page and search for the extension.

Common extensions and what needs them

ExtensionTypically needed by
mysqli / pdo_mysqlWordPress, Laravel, any MySQL app
gd or imagickImage resizing and thumbnails
intlLaravel, Magento, WooCommerce, localisation
mbstringMultibyte text, most frameworks
zipPlugin and theme installs, Composer
curlAPI calls, updates
opcachePerformance; enable everywhere
redis / apcuObject caching

Troubleshooting

  • Extension shows in CLI but not on the website: you installed it for a different version than PHP-FPM uses, or did not restart FPM.
  • PHP Warning: Module already loaded: the extension is enabled twice; remove the duplicate ini file.
  • Unable to load dynamic library: the .so was built for another PHP version. Reinstall the package for the correct version.

PHP extensions FAQ

How do I enable extensions on cPanel hosting?

Use cPanel → Software → Select PHP Version (CloudLinux PHP Selector) and tick the extensions; no root access needed.

Should I enable Xdebug in production?

No. It slows PHP considerably; use it only on development servers.

Do extensions survive a PHP upgrade?

Packaged extensions must be installed again for the new version (e.g. php8.4-intl).

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.