How to Enable cURL in PHP on XAMPP
cURL is a fundamental tool for modern PHP development, allowing you to perform HTTP requests from your server. Whether you are fetching JSON data from an external API or pushing information to a third-party service, having the curl extension enabled is non-negotiable. However, environments like XAMPP often ship with this extension disabled by default to maintain a minimal installation footprint. This guide explains exactly how to enable it and ensures the configuration persists across your local development stack.
The most common scenario involves locating the php.ini file associated with your PHP installation within the XAMPP directory structure. Unlike standard Linux distributions where php.ini might be in /etc/php/, XAMPP typically places this configuration file inside the php\extras\php\ folder or directly within the main php folder of your installation root.
Before making changes, verify which configuration file is actually active. You can do this by creating a temporary test script with <?php phpinfo(); ?> and searching for "cURL". If you see nothing, the extension is not loaded. If it is present but disabled, look for a line resembling ; curl.cnt = 1. The semicolon indicates it is commented out. You need to remove that semicolon or explicitly set the directive to 1.
Once you have edited the primary php.ini, XAMPP usually requires a restart of the Apache service to pick up these changes. Simply saving the file is insufficient because Apache loads extensions into memory at startup. Open your XAMPP Control Panel, stop the Apache server, and then click Start again. If you are using a separate PHP CLI installation managed by XAMPP, ensure that specific php.ini file (often found in xampp\php\php.ini) is also updated if you intend to run CLI scripts like composer.phar.
Sometimes, editing the main php.ini is not enough because the server is actually running a different configuration file. This often happens when php.ini-development or php.ini-production is symlinked to the active configuration. In such cases, simply uncommenting the line in the master file won't work; you must edit the specific file that phpinfo() points to. You can find the exact path used by checking the "Loaded Configuration File" entry in your phpinfo() output.
If you are building a Laravel application on top of XAMPP, enabling cURL is equally critical for interacting with external services or sending notifications via webhooks. Without it, features relying on HTTP clients will throw fatal errors regarding missing extensions. The process remains identical regardless of the framework, but the impact on your application's functionality is significant.
There are alternative methods to enable cURL without modifying php.ini directly, though they come with their own trade-offs. You can use a .user.ini file in your project root or an Apache .htaccess directive if you have that enabled. However, these approaches are less common for enabling extensions and can sometimes be overridden by global settings depending on the XAMPP version. For most cases, editing the central php.ini remains the most robust solution.
Finally, always verify your environment after making changes. Running a simple check in your terminal or browser confirms that the extension is loaded. If you encounter issues where the extension appears enabled but functions incorrectly, check for conflicting ini_set() calls or opcode cache problems that might prevent the new configuration from taking effect immediately.