PHP says curl_init() does not exist because an extension is missing
PHP Fatal error: Uncaught Error: Call to undefined function curl_init()Short answer
The function belongs to an extension (curl, mbstring, xml and others) that the PHP process running your code has not loaded. Check the loaded extensions of that exact process, not of the php command in your terminal, then install or enable the extension for that PHP version and restart PHP-FPM or Apache.
Fix it fast
1Find out which cause you have
List the extensions of command line PHP, then ask the web side the same question through a temporary page, because CLI and web PHP are separate programs with separate settings. The temporary page prints the PHP version, the interface and whether curl is loaded.
php -m | grep -i curl echo '<?php echo PHP_VERSION, " ", php_sapi_name(), " curl=", var_export(extension_loaded("curl"), true);' | sudo tee /var/www/html/ext-probe.php curl -s http://127.0.0.1/ext-probe.php; echo; sudo rm /var/www/html/ext-probe.php2Match what you see, then jump to its fix
- 1
php -m does not list curl, and the web probe prints curl=falseThe extension package is not installedFix - 2
The file exists (the DLL on Windows, or the package on Linux), but php -m still lacks itThe extension is installed but switched off in php.iniFix - 3
php -m shows curl, but the web probe prints curl=false, or prints another version numberThe web server runs a different PHP than the php commandFix - 4
The error appears only inside the container, and php -m in the container does not list the extensionA Docker php image does not include the extensionFix
- 1
What does the error look like?
PHP Fatal error: Uncaught Error: Call to undefined function curl_init()Fatal error: Call to undefined function mb_strlen()Class "DOMDocument" not found
Cause 1 of 4
The extension package is not installed
1Check
On Debian and Ubuntu each extension is its own package, named after the PHP version. See which PHP packages are installed and whether one for curl exists.
dpkg -l 'php*' | grep -E 'curl|fpm|cli'2Fix
Install the package for your PHP version, then restart the service that runs PHP so it loads the new extension. Use apache2 instead of php8.3-fpm if Apache runs PHP as a module.
sudo apt install php8.3-curl
sudo systemctl restart php8.3-fpm3Verify
The extension is listed and the web probe prints curl=true.
php -m | grep -i curlConfirmed by packages.ubuntu.com
Cause 2 of 4
The extension is installed but switched off in php.ini
1Check
PHP reads the main php.ini plus the extra .ini files from a scan folder. On Windows the extension line in the main file is commented out with a semicolon by default. Find the files PHP loaded.
php --ini
php -i | grep -i 'curl'2Fix
Remove the semicolon in front of the extension line in the php.ini that php --ini reports. On Windows the PHP manual also asks for the OpenSSL and libssh2 DLLs to be on the PATH. Restart the web server afterwards.
; php.ini
extension=curl3Verify
A new php process lists curl.
php -m | grep -i curlConfirmed by php.net
Cause 3 of 4
The web server runs a different PHP than the php command
1Check
Several PHP versions can live on one machine. The one in your terminal (php -v) is not necessarily the one behind PHP-FPM or Apache, and each has its own php.ini. Compare the version from the probe in the first step with the terminal's version.
php -v | head -n 1
systemctl list-units 'php*-fpm*' --no-legend2Fix
Install or enable the extension for the version that the probe printed, and restart that service. If you want both to use the same version, switch the command line default instead.
sudo apt install php8.2-curl # example: the web side runs 8.2
sudo systemctl restart php8.2-fpm3Verify
The web probe prints curl=true.
curl -s http://127.0.0.1/ext-probe.phpConfirmed by php.net
Cause 4 of 4
A Docker php image does not include the extension
1Check
The official image compiles in many extensions, but not every one, and the list depends on the PHP version. Ask the container itself.
docker run --rm php:8.3-fpm php -m2Fix
Add the extension in the Dockerfile with the image's helper script. Extensions that need system libraries (gd, for example) need their development packages installed first.
FROM php:8.3-fpm
RUN docker-php-ext-install -j"$(nproc)" mysqli3Verify
Rebuild the image and check the list.
docker build -t my-php .
docker run --rm my-php php -m | grep -i mysqliConfirmed by hub.docker.com
How do I stop it coming back?
- Write the extensions your app needs into composer.json (ext-curl, ext-mbstring) so composer install fails with a clear message on a server that lacks them.
- Check Laravel's list of required extensions when you provision a server, instead of adding them one error at a time.
- Use one PHP version per server, or name the version in every command and service.
- After a PHP upgrade, repeat the web probe; extension packages are per version and do not move over.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
Related fixes
Back end
imagecreatetruecolor() is undefined because the GD extension is missing
Fatal error: Uncaught Error: Call to undefined function imagecreatetruecolor()
All imagecreate* and imagecreatetruecolor functions come from the GD extension.
3 causes, each with a fixBack end
PHP cannot turn a hostname into an IP address
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed
This warning means the operating system could not resolve the hostname PHP was asked to connect to.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack end
CodeIgniter 4 cannot write its cache files
CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/
CodeIgniter 4's file cache needs a cache directory that the web server can really write to.
2 causes, each with a fix