keepcalculator

06 Numbers and Powers

Fix cURL Not Installed in PHP: Step-by-Step Guide

Card No. 06·4079 · Updated · Standard formula, shown below

If you’re seeing an error like Call to undefined function curl_init() or cURL is not installed in your PHP application, it means the cURL extension is either missing, disabled, or not properly configured in your PHP environment. This guide walks you through installing and enabling cURL on Windows, Linux, and macOS, covering both the PHP extension and the underlying libcurl library.

What You’ll Need

  • Access to your server or local machine’s terminal/command prompt.
  • Administrator or sudo privileges (for installing packages).
  • Knowledge of your PHP version (run php -v).
  • Your PHP installation path (especially on Windows).

Step-by-Step

Step 1: Verify cURL is Actually Missing

First, confirm that cURL is not loaded. Run the following command in your terminal:

php -m | grep curl

If nothing appears, cURL is not enabled. You can also check with php -i | grep curl or create a temporary PHP file with <?php phpinfo(); ?> and look for the cURL section.

Step 2: Install cURL on Linux (Debian/Ubuntu)

For most Linux distributions, cURL is available as a package. On Debian-based systems, run:

sudo apt update
sudo apt install php-curl

This installs the cURL extension for your default PHP version. If you’re using a specific PHP version (e.g., PHP 8.1), you may need:

sudo apt install php8.1-curl

After installation, restart your web server:

sudo systemctl restart apache2   # or nginx, php-fpm

Step 3: Install cURL on Linux (RHEL/CentOS/Fedora)

For Red Hat-based systems, use yum or dnf:

sudo yum install php-curl   # or dnf install php-curl

Then restart the web server or PHP-FPM service.

Step 4: Enable cURL on Windows

On Windows, the cURL extension is bundled with PHP but often disabled by default. Follow these steps:

  1. Locate your php.ini file (usually in your PHP installation directory, e.g., C:\php\php.ini).
  2. Open it in a text editor.
  3. Find the line ;extension=curl and remove the semicolon at the beginning to uncomment it.
  4. If you’re using PHP 7.4 or later, you may also need to enable extension=php_curl.dll (the exact name depends on your PHP version).
  5. Save the file and restart your web server (Apache, IIS, or the PHP built-in server).

Also ensure that the libcurl.dll file is present in your PHP directory or in the system PATH. If not, you may need to download the correct version for your PHP build (Thread Safe vs Non-Thread Safe).

Step 5: Enable cURL on macOS (Homebrew)

If you installed PHP via Homebrew, cURL is usually included but might need to be enabled in php.ini. Run:

brew install php-curl

Or simply uncomment the extension=curl line in your php.ini file. The path to php.ini can be found with php --ini.

Step 6: Restart Your Web Server

After installing or enabling cURL, you must restart your web server or PHP-FPM service for changes to take effect. Common commands:

sudo systemctl restart apache2   # Debian/Ubuntu
sudo systemctl restart nginx     # if using PHP-FPM, also restart php-fpm
sudo service httpd restart       # RHEL/CentOS

On Windows, restart Apache via the system tray icon or the services.msc console.

Step 7: Verify cURL is Now Loaded

Run the same command as before:

php -m | grep curl

You should see curl in the output. Also, check phpinfo() again to see the cURL section with version details.

Step 8: Test with a Simple Script

Create a PHP file with the following content and access it in your browser or run it via CLI:

<?php
if (function_exists('curl_init')) {
    echo 'cURL is enabled';
} else {
    echo 'cURL is NOT enabled';
}
?>

You should see the success message.

Common Mistakes

  • Editing the wrong php.ini – There may be multiple php.ini files (CLI vs web server). Use php --ini to find the correct one.
  • Forgetting to restart the server – Changes to php.ini won’t take effect until the server is restarted.
  • Using the wrong extension file name – On Windows, the extension might be php_curl.dll in older PHP versions, but in PHP 8 it’s just curl. Check your PHP version’s documentation.
  • Missing libcurl dependency – On Linux, if libcurl is not installed, the extension may fail to load. Install it with sudo apt install libcurl4 or sudo yum install libcurl.
  • Mixing 32-bit and 64-bit binaries – Ensure your PHP and extension are both 32-bit or both 64-bit.

Tips

  • Always use your package manager to install PHP extensions when possible – it handles dependencies automatically.
  • If you’re using a control panel like cPanel or Plesk, use its PHP extension manager instead of manual installation.
  • For Docker containers, add the cURL extension to your Dockerfile, e.g., RUN docker-php-ext-install curl for official PHP images.
  • Keep your PHP and extensions up to date to avoid security vulnerabilities.

Troubleshooting

cURL still not showing after installation

Check if the extension is being loaded by looking at the error log. On Linux, run php -v and see if there are any warnings. Also, verify that the extension file exists in the correct directory (e.g., /usr/lib/php/20210902/curl.so).

“PHP Startup: Unable to load dynamic library ‘curl’â€�

This error indicates that the extension file is missing or incompatible. On Windows, ensure that the php_curl.dll file is in the ext folder and that the extension_dir in php.ini points to the correct location. On Linux, reinstall the package or try compiling from source.

cURL works in CLI but not in the web server

This usually happens when the CLI and web server use different php.ini files. Check which php.ini the web server is using by looking at phpinfo() in a browser. Then edit the correct file.

“cURL error: SSL certificate problem�

This is not an installation issue but a configuration one. You may need to update your CA certificates or set curl.cainfo in php.ini to the path of a valid CA bundle.

Frequently Asked Questions

How do I check if cURL is enabled in PHP?

Run php -m | grep curl in the terminal, or create a PHP file with <?php phpinfo(); ?> and look for the cURL section.

Do I need to install libcurl separately?

On Linux, yes – the PHP cURL extension requires the libcurl library. On Windows and macOS, it’s usually bundled with PHP or installed automatically.

Why does cURL work in the command line but not in the browser?

This is because the CLI and the web server use different PHP configurations. Ensure you’ve enabled cURL in the php.ini file used by the web server.

Can I use cURL without installing it?

No, cURL is a required extension for many PHP functions like curl_init(). Without it, you’d need to use alternative HTTP libraries like Guzzle (which still requires cURL) or file_get_contents with stream contexts.

What if my hosting provider doesn’t allow installing extensions?

Some shared hosts have cURL enabled by default. If not, contact your provider – they may enable it for you. Alternatively, you can use a VPS or dedicated server where you have full control.

Is cURL safe to enable?

Yes, cURL is a standard, widely-used extension. It’s safe as long as you keep your PHP and libcurl updated to the latest versions.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →