How to Install and Enable Common PHP Extensions on Ubuntu and Debian

A stylized server block with a module cartridge sliding into it. Text: INSTALL PHP EXTENSIONS

We may earn a referral fee at no additional cost to you when you shop through the links on this page.

Your app refused to start over a missing PHP extension, or a checklist wants six of them installed. This DevAnswers guide covers PHP extensions on Ubuntu and Debian without the classic traps: the wrong-version metapackage, the enable step, and the restart that makes php -m and your web app agree.

Quick Answer: Install, Restart, Verify 

Install version-pinned extension packages matching php -v, restart the service that runs your PHP, and confirm with php -m:

Terminal
sudo apt install php8.3-curl php8.3-gd php8.3-mbstring php8.3-xml php8.3-zip php8.3-mysql php8.3-intl php8.3-bcmath && sudo systemctl restart php8.3-fpm && php -m

Swap 8.3 for your version, and swap php8.3-fpm for apache2 if you run mod_php instead of PHP-FPM. The restart is what makes your web app agree with the terminal; the sections below explain the version trap, the enable step, and what WordPress and Laravel actually need.

How PHP Extensions Work on Ubuntu and Debian 

Debian-family PHP is packaged per version and per extension: the curl extension for PHP 8.3 is the apt package php8.3-curl, and so on. Installing one drops an ini fragment into /etc/php/8.3/mods-available/, which gets linked into a conf.d directory for each SAPI (CLI, FPM, Apache); any .ini file in that scan directory is loaded by PHP. The phpenmod and phpdismod helpers manage those links, though apt normally enables a freshly installed extension for you.

Match Your PHP Version First 

The number one failure in this job is installing an extension for a PHP version your app doesn’t run. Check what you actually have before installing anything. Note php -v reports the command-line version; if a website is the target, check the version its web server actually runs (a phpinfo() page, or php-fpm8.3 -v for the matching FPM service) because a multi-version host can run a different PHP for the web than for the CLI:

Terminal
php -v

Unversioned packages like php-curl are metapackages: they track the distribution’s default PHP version, not necessarily yours. On a box with one PHP that distinction is invisible; the moment two versions coexist (a Sury upgrade, a leftover 8.1), the metapackage can cheerfully install the extension for the wrong one. Version-pinned names like php8.3-curl remove the ambiguity, so this guide uses them throughout; swap 8.3 for your version. For reference: Ubuntu 24.04 ships PHP 8.3 by default and Ubuntu 26.04 ships PHP 8.5, so on a fresh 26.04 box every versioned package in this guide becomes php8.5-*.

Install the Common Extensions 

The workhorse set for web applications, in one line:

Terminal
sudo apt install php8.3-curl php8.3-gd php8.3-mbstring php8.3-xml php8.3-zip php8.3-mysql php8.3-intl php8.3-bcmath
  • curl: outbound HTTP requests (APIs, webhooks, updaters)
  • gd: image creation and manipulation (thumbnails, crops); PHP’s image functions require the GD library, which itself leans on further libraries per image format
  • mbstring: multibyte string handling (any non-ASCII text)
  • xml: XML handling: DOM, SimpleXML, readers and writers (feeds, sitemaps)
  • zip: reading and writing archives (plugin/theme installs, exports)
  • mysql: the MySQL/MariaDB drivers (mysqli and pdo_mysql)
  • intl: locale-aware formatting and internationalization
  • bcmath: arbitrary-precision arithmetic (money, big integers)

No need to hunt down system libraries first: Debian’s packaging encodes shared-library dependencies, so apt pulls in what each extension needs (libpng for gd and friends) automatically.

Enable, Restart, Verify 

Apt usually enables what it installs. When you need to do it by hand (or re-enable something disabled earlier), phpenmod does the linking, and the service that runs your PHP must restart to load the new module:

Terminal
sudo phpenmod curl && sudo systemctl restart php8.3-fpm

Under Apache with mod_php, restart Apache instead with sudo systemctl restart apache2. Then confirm the modules are enabled; php -m answers for the CLI, and the restart you just ran is what brings the web SAPI along (the next section covers the trap when the two disagree):

Terminal
php -m | grep -Ei 'curl|gd|mbstring'
Output
curl
gd
mbstring

Why the Terminal Says Yes but Your App Says No 

Here’s the trap that generates half the confusion on this topic. php -m asks the CLI, but the CLI and PHP-FPM are different SAPIs with separate configuration setups, and FPM only takes on configuration changes at a service restart or reload. So the terminal can happily list an extension while the web app, still running on the pre-install FPM workers, throws “Call to undefined function”. The fix is almost always the restart you skipped: systemctl restart php8.3-fpm. To check what the web SAPI sees, use a temporary phpinfo() file rather than the terminal. The curl_init() error guide walks this exact diagnosis end to end. Delete that file as soon as you are done: a public phpinfo() page hands your entire PHP configuration to anyone who requests it.

What WordPress and Laravel Actually Need 

For WordPress, the hosting handbook is precise: mysqli is required, while curl, dom, exif, fileinfo, imagick, intl, mbstring and zip are recommended; WordPress runs without the recommended set but works harder or drops functionality. The one-liner above covers most of it; add the imagick extension (its own small saga); dom is already covered by the php8.3-xml package in the bundle.

For Laravel, the deployment docs list the minimum extensions the server needs (ctype, curl, dom, fileinfo, filter, hash, mbstring, openssl, pcre, pdo, session, tokenizer, xml at the time of writing). Most of those ship inside the core php8.3-common/php8.3-cli packages. A typical Laravel box installs the remaining gaps plus the zip and database-driver packages Composer and most apps expect:

Terminal
sudo apt install php8.3-curl php8.3-mbstring php8.3-xml php8.3-mysql php8.3-zip

When the Repo Doesn’t Have It: PECL and Sury 

Two situations push you past the default repos. First, an extension with no apt package at all: that’s PECL territory, which compiles the extension locally and needs the PEAR tooling plus PHP’s development headers:

Terminal
sudo apt install php-pear php8.3-dev && sudo pecl install extension_name

On Debian-family systems PECL stops at the compile: it drops the .so in place but never wires the mods-available plumbing, so the module stays unloaded until you do that part yourself. One more multi-version caveat: PECL compiles against the system-default PHP, so confirm php-config --version matches your target before building:

Terminal
echo 'extension=extension_name.so' | sudo tee /etc/php/8.3/mods-available/extension_name.ini
sudo phpenmod -v 8.3 extension_name && sudo systemctl restart php8.3-fpm

Prefer the apt package whenever one exists; it upgrades with the system, while PECL builds are your responsibility after every PHP update. Second, a PHP version newer than your distro ships: upgrading PHP via the Sury repository (ppa:ondrej/php on Ubuntu, packages.sury.org on Debian) gets you current PHP versions with the full extension set, packaged in exactly the phpX.Y-name scheme this guide uses.

Next Steps 

Extensions installed, loaded, and proven against the right SAPI. When an extension needs settings rather than just enabling (memory limits, upload sizes, per-extension ini options), the next stop is finding and editing the right php.ini for the SAPI that runs your code.

Support DevAnswers
Written, tested and maintained by one developer. Your support keeps these guides accurate and ad-light.
Buy me a coffee

Comments

Leave a reply