php runtime and server environment
Extensions
PHP extensions add capabilities to the runtime. Some provide core features such as JSON, PDO, and OpenSSL. Others add optional integrations such as Redis, Imagick, Xdebug, or database drivers.
Extension problems are common in real projects: Composer refuses to install, a framework feature is missing, image uploads fail, database drivers are unavailable, or code works in CLI but not through the web server.
Built-In And Shared Extensions
Some extensions are compiled into PHP or enabled by default. Others are shared modules loaded through configuration.
List loaded extensions:
php -m
Check details:
php -i | grep extension_dir
php --ini
From PHP:
<?php
declare(strict_types=1);
echo extension_loaded('mbstring') ? 'mbstring loaded' : 'mbstring missing';
echo PHP_EOL;
// Prints:
// mbstring loaded
Do not assume an extension exists because your code editor recognises a function. Prove it in the runtime that runs the project.
Common Extensions In PHP Jobs
Common application extensions:
pdofor database abstractionpdo_mysql,pdo_pgsql, orpdo_sqlitefor database driversmbstringfor multibyte string functionsintlfor locale-aware formatting and transliterationcurlfor HTTP requestsopensslfor TLS and cryptography supportjsonfor JSON encoding and decodingzipfor archivesgdorimagickfor image workfileinfofor MIME type detectionredisfor Redis integrationopcachefor bytecode cachingxdebugfor debugging and coverage in development
Not every project needs all of these. The project should declare what it needs.
Enabling Extensions
Extensions are commonly enabled in .ini files:
extension=mbstring
extension=pdo_mysql
extension=redis
zend_extension=opcache
Use zend_extension for Zend engine extensions such as OPcache and Xdebug. Use extension for normal PHP extensions.
The actual package name and config path depend on operating system, PHP version, and installation method.
Composer ext-* Requirements
Composer can declare extension requirements:
{
"require": {
"php": "^8.3",
"ext-mbstring": "*",
"ext-pdo": "*",
"ext-openssl": "*"
}
}
Check the active runtime:
composer check-platform-reqs
This is better than discovering missing extensions during a request in production.
CLI And Web Extension Mismatches
CLI and web PHP can have different extension sets.
Check CLI:
php -m
php --ini
Check web runtime with a diagnostic:
<?php
declare(strict_types=1);
header('Content-Type: text/plain');
foreach (['mbstring', 'intl', 'pdo_mysql', 'opcache'] as $extension) {
echo $extension . ': ';
echo extension_loaded($extension) ? 'loaded' : 'missing';
echo PHP_EOL;
}
If the results differ, compare loaded php.ini files and scanned .ini directories for the two SAPIs.
Extension Functions And Classes
Extensions often provide functions, classes, constants, or stream wrappers.
Examples:
<?php
declare(strict_types=1);
if (!extension_loaded('intl')) {
echo 'intl is required for this formatter' . PHP_EOL;
exit(1);
}
$formatter = new NumberFormatter('en_GB', NumberFormatter::CURRENCY);
echo $formatter->formatCurrency(12.34, 'GBP') . PHP_EOL;
This check fails early with a clear message instead of producing a confusing class-not-found error later.
Development-Only Extensions
Some extensions should usually be limited to development and CI.
Xdebug is useful for step debugging and coverage, but it can slow down requests. It should not normally be enabled in production web traffic.
OPcache is different. It is a performance extension and should normally be enabled in production.
The question is not only "is the extension installed?" It is "should this extension be enabled in this environment?"
What You Should Be Able To Do
After this lesson, you should be able to list loaded extensions, check an extension from PHP code, understand extension versus zend_extension, read Composer ext-* requirements, and debug mismatches between CLI and web extension sets.
For junior PHP work, this matters because missing extensions are setup bugs that look like code bugs. A good developer verifies the platform before rewriting working code.
Practice
Practice: Check Required Extensions
Create a small extension diagnostic for a PHP project.
Task
Build a PHP script that checks:
mbstringintlpdopdo_mysqlopcache
The script should print loaded or missing for each extension and exit with 1 if any required extension is missing. Treat opcache as recommended rather than required.
Use strict types. Keep example output inside the PHP code block as comments.
Afterward, add a short note explaining how this relates to composer check-platform-reqs.
Show solution
This script separates required extensions from recommended ones.
<?php
declare(strict_types=1);
$requiredExtensions = ['mbstring', 'intl', 'pdo', 'pdo_mysql'];
$recommendedExtensions = ['opcache'];
$missingRequired = [];
foreach ($requiredExtensions as $extension) {
$loaded = extension_loaded($extension);
echo $extension . ': ' . ($loaded ? 'loaded' : 'missing') . PHP_EOL;
if (!$loaded) {
$missingRequired[] = $extension;
}
}
foreach ($recommendedExtensions as $extension) {
$loaded = extension_loaded($extension);
echo $extension . ': ' . ($loaded ? 'loaded' : 'missing') . ' (recommended)' . PHP_EOL;
}
if ($missingRequired !== []) {
fwrite(STDERR, 'Missing required extensions: ' . implode(', ', $missingRequired) . PHP_EOL);
exit(1);
}
exit(0);
// Prints:
// mbstring: loaded
// intl: loaded
// pdo: loaded
// pdo_mysql: loaded
// opcache: loaded (recommended)
composer check-platform-reqs checks the project's declared ext-* requirements against the active PHP runtime. This script is a focused diagnostic; Composer is the source of truth when the project declares its extension requirements properly.