Menu
InformatiWeb
  • Index
  • Courses
  • Tutorials
  • InformatiWeb Pro

Login

Registration Password lost ?
FR
  • IT
    • Articles
    • Backup
    • BIOS
    • Live CD
    • MultiBoot
    • Security
    • Virtualization
    • Web
    • Windows
  • InformatiWeb
  • Tutorials
  • IT
  • Web
  • Enable curl extension of PHP on Windows
  • Web
  • 18 November 2013 at 21:18 UTC
  • Lionel

Enable curl extension of PHP on Windows

If you've ever tried to use the "curl" of PHP on Windows, you may have noticed that PHP you return an error stating that the "curl_init()" function (or another function curl) was not defined.
The reason is simple : this extension is not enabled by default in PHP.

  1. Enable the "curl" extension in php.ini
  2. Add the path to the PHP file in the environment variable "PATH" Windows.
  3. Restart the Apache service take into account changes
  4. Test the curl extension through our example

1. Enable the "curl" extension in php.ini

First, to enable the "curl" extension to PHP, you have 2 options:
- Either you have WAMP :
In this case, you can activate it by clicking on the WAMP (left-click) and then going to "PHP -> PHP extensions". Then click "php_curl" to a "v" appears next.
- Either you installed PHP from the official website of the author :
In this case, you need to edit the "php.ini" file located in the root folder of PHP.
In this file, uncomment the following line by removing the ";" if present (or add it if it is not there) :

Apache

;extension=php_curl.dll

2. Add the path to the PHP file in the environment variable "PATH" Windows.

As stated on the official website of PHP curl module needs DLLs "libeay32.dll" and "ssleay32.dll" to work.

So PHP can find and use so you have 2 solutions :
- Either copy the folder C:\Windows\System32
- Either add the folder path in the PHP environment "PATH" variable of Windows. (Recommended)

To add, modify the variable by adding the path to the PHP file at the end of this variable, separating by ;

Note : If you don't know how to change an environment variable, take a look at our tutorial : Change and / or display environment variables in Windows

3. Restart the Apache service take into account changes

To restart the Apache service is the web server running PHP as a module :
- Launch the "services.msc program
- Select "Apache" (named "wampapache" with WAMP) service
- Then click Restart (in the right column)

For more information on managing services in Windows, take a look at our tutorial : Managing Windows Services

4. Test the curl extension through our example

Here is a PHP script that will show you the Wikipedia page on curl.

PHP

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Example of using curl</title>
</head>

<body>
<?php
// URL of the page you want to retrieve the content (more precisely : the source code)
$url = 'https://fr.wikipedia.org/wiki/CURL';
// Initialize a cURL session
$ch = curl_init();

// Set some options
// - Specifies the URL which curl will access
curl_setopt($ch, CURLOPT_URL, $url);
// - Return the content by the curl_exec function instead of displaying content directly recovered
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// - Set a user-agent to send to the server. For example, you can send a user-agent of an Android phone, iPhone, ... to try to recover the contents of a mobile version of a website
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0');
// - Execute the cURL session and stores the retrieved content in the variable $ result (through CURLOPT_RETURNTRANSFER optional)
$resultat = curl_exec ($ch);
// - Close a cURL session and thus the connection to the remote server
curl_close($ch);

// Displays the contents recovered by curl
echo $resultat;
?>
</body>
</html>

Share this tutorial

Partager
Tweet

To see also

  • Adobe Fireworks - Batch process

    Web 6/12/2014

    Adobe Fireworks - Batch process

  • Configure and secure your wireless network

    Web 11/3/2013

    Configure and secure your wireless network

  • Eclipse - Connect to a remote file system

    Web 1/12/2014

    Eclipse - Connect to a remote file system

  • OVH - Change contacts of your domain

    Web 7/2/2013

    OVH - Change contacts of your domain

Comments

You must be logged in to post a comment

Share your opinion

Pinned content

  • Useful softwares
  • Our programs
  • Terms and conditions
  • Share your opinion

InformatiWeb Pro

  • Win. Server administration
  • Linux Administration
  • Virtualization

Contact

  • Guest book
  • Technical support
  • Contact

® InformatiWeb.net 2008-2022 - © Lionel Eppe - All rights reserved.

Total or partial reproduction of this site is prohibited and constitutes an infringement punishable by articles L.335-2 and following of the intellectual property Code.