The other day I wanted to install a WordPress plugin on a website hosted on my Windows local development machine, but the plugin complained that it needs the cURL extension enabled on the
php.ini configuration file. This seemed like an easy problem to solve, but after modifying the
php.ini file, I was still getting the "curl not found" error. This article will show two different ways to make the cURL extension work on the Windows system.
Whichever solution we use, we first need to enable the cURL extension in the
php.ini file. If you have already done that and the cURL is still not available, skip to the next section.
Enabling cURL extension in php.ini file
php.ini is a PHP configuration file and among other settings, it has a list of extensions that are commented out and disabled by default.
In the steps below, we are going to enable the cURL extension.
- First, we need to locate the PHP folder. It's usually at
C:\php, but it really depends on how it was installed in the first place. You could try to run the following code to find the location of the PHP directory:
<?php echo PHP_BINDIR; ?>
- Inside the PHP directory, there should be a
php.inifile. Open it with the text editor and search for the following line:
;extension=curlNote: On older PHP versions, you might have
;extension=curlin the php.ini file.
- Uncomment that line by removing the semicolon
;character and save the changes.
- Restart the web server.
Removing the comment of the extension in
php.ini, saving the changes, and restarting the server should be enough to enable most extensions, but in my case, with the cURL, it was still not working.
Why cURL extension was still not enabled
It turns out, the reason why cURL cannot be found is that Windows needs to know the location of the following .dll file:
This dynamic link library file is located in the root of the PHP folder, but the problem is Windows doesn't look for .dll files there.
In the end, I was able to make it work using two different solutions. One solution is quick, but a little "hacky", while the other takes a bit more time, but is a more complete solution.
Solution 1 - Copy the libssh2.dll into Windows System folder
In this solution, we simply copy the required
libssh2.dll into the Windows System folder, so that Windows finds the libssh2.dll file.
- In the File Explorer, go to the folder where PHP is located.
- Inside it, you should see the
libssh2.dllfile. Copy it.
- Go to the
C:\Windows\System32and Paste the file there.
- Restart the web server.
Now the cURL PHP extension should work.
This solution is pretty simple, but the problem with it is that if you update the PHP in the future, you might forget to again copy the newer
libssh2.dll to the Windows System folder.
A much better solution is to let Windows know about the location of the PHP folder using the Path environment variable.
Solution 2 - Add PHP folder into the System Path variable
Instead of copying
libssh2.dll into a Windows System folder, a much cleaner solution is to add the location of the PHP folder into the System Environment Path variable. This way, if you update a PHP in the future on the same folder, nothing else needs to be done.
The steps are as follow:
In Windows Search field, look for "env". You should see two results, one to edit "environment variables" and the other to edit "system environment variables".
Select the "Edit the system environment variables" from the search result as shown below.
- The "System Properties" windows should open up. Click on the "Environment Variables..." button at the bottom of the window.
The "Environment Variables" window should now open. The first list at the top of the window contains user variables, while the bottom list contains system variables. We need to edit the Path in system variables.
In the bottom list for "System Variables", select the "Path" variable and click the "Edit" button (located near the OK button).
- You should now see the list of locations that are in the Path variable. Click on the New button to add a new location.
- Paste the location of the PHP folder. For example,
C:\phpas shown below.
- Click on OK to close the window of Path locations and again click OK to close both the "Environment Variables" and "System Properties" windows.
- Restart the web server. If restarting the server doesn't work, restarting the computer should do the trick.
The PHP cURL extension should now be active, so let's test if this is indeed the case.
Testing if PHP cURL extension really is enabled
We could confirm that the cURL is working by using the phpinfo() function that outputs all the PHP configuration information, but to just check for the cURL extension, we can use the following code:
<?php var_dump(extension_loaded("curl")); ?>
If it is enabled, the script will display bool(true), if on other hand it is still not enabled, it will display bool(false). In that case, double-check that you didn't add the PHP location in Path for user variables. Having a location for PHP folder there will not work.
PHP has many extensions that are disabled by default in the
php.ini file. To enable an extension, we just need to uncomment it, but with the cURL extension, just uncommenting the
extension=curl line might not be enough.
We learned two different ways to make cURL work on Windows. One way is to manually copy the
libssh2.dll file to the Windows system folder, but a better solution is to tell Windows where the .dll file is by adding the location of the PHP folder in the Path System environment variable.