Call to undefined function curl init windows

Call to undefined function curl_init() even it is enabled in php7

I’ve just installed php7 to my Ubuntu. At first, there was no problem, my web site was working. But suddenly, it started to return Call to undefined function curl_init() error. Now, my pages contain curl codes do not work.

In phpinfo(), it looks Curl is enabled. There were similar questions but none of them handled it in php7. I thought it should be something different than others.

Edit: When I try

in terminal, it returns

10 Answers 10

I’ve had similar problem with curl after upgrade to XX (16.04). After reinstalling curl with:

And server restart

everything went back to normal 🙂

Assumption

You’ve installed the version of the module for the PHP version you are using, and yet the problem is not going away.

There could be multiple versions of PHP installed on your system and Apache is not using the version you are expecting it to use.

How do you know which version of PHP Apache is using?

To know this, the key idea is to learn the ROOT directory of your Apache’s configuration files. In the command line, you can type:

In my case, my Apache’s ROOT configuration directory is shown in the

Now that I know the location of the configs that Apache is using, I can now accurately determine the version of PHP it is using by examining the «mods-enabled» directory located inside the «/etc/apache2» directory.

In my case, when do an ls while inside the «mods-enabled» , it showed the ff output:

At this point, I now know for certain that Apache is using the ‘php5’ version of PHP installed on my system, whatever that may be.

Then I tried to reproduce the error above using this version of PHP (i.e., ‘php5’ ) by running the command below:

The version of PHP that I expected my Apache was using is «php5.6» and running the same command above with this version did not produce the said error.

Solution

To solve this problem, you either install the version of the module that corresponds to the PHP version that Apache is using (in my example php5.0-curl) or you may change the version of PHP that is being used in Apache to the version you want.

How do I tell Apache which version of PHP to use?

You can accomplish this using the a2enmod/a2dismod cli commands of Apache2.

Firstly, I disable the PHP module that is currently active on my server (i.e., «php5» ):

Then I enabled the php module for the version of PHP that I want my Apache to use:

Then I restart Apache

After I refreshed the offending page on my website, the error is now gone.

Fatal error: Call to undefined function curl_init() using Batch File

I have a PHP that downloads files from backend. I am using WAMP in Windows 7 and it works perfectly when done through the browser.

Now I have created a batch file to execute the php and it shows:

Fatal error: Call to undefined function curl_init()

Not sure why something that could work over in browser is not working in batch file. Below is my code for the batch file:

Читайте также:  Fprint vcom драйвер windows

Any idea what’s the issue?

4 Answers 4

uncomment the following on your php.ini

and restart webserver. This might be due to curl disabled in your php.

When you use wamp, xamp or other all-in-one server, it uses an overrided php.ini located into bin/conf/ instead where original is.

You need copy from these or edit the ini located at php.exe folder.

If you cant access it (shared server, etc), you can create a custom php.ini file into script folder, and put needed instructions:

When using through browser it is using WAMP and the PHP ini is from C:\wamp\bin\php\php5.4.3

But I have set my php directory to C:\php-5.4.9 in environmental variables, thus when using windows batch it is calling php from that directory and there was no php.ini file there.

I copied the PHP ini file from wamp to php folder and now it is working.

Apparently I have installed php and then wamp, thus there is a overlap which has caused confusion.

Call to undefined function curl_init() even it is enabled in php7

I’ve just installed php7 to my Ubuntu. At first, there was no problem, my web site was working. But suddenly, it started to return Call to undefined function curl_init() error. Now, my pages contain curl codes do not work.

In phpinfo(), it looks Curl is enabled. There were similar questions but none of them handled it in php7. I thought it should be something different than others.

Edit: When I try

in terminal, it returns

10 Answers 10

I’ve had similar problem with curl after upgrade to XX (16.04). After reinstalling curl with:

And server restart

everything went back to normal 🙂

Assumption

You’ve installed the version of the module for the PHP version you are using, and yet the problem is not going away.

There could be multiple versions of PHP installed on your system and Apache is not using the version you are expecting it to use.

How do you know which version of PHP Apache is using?

To know this, the key idea is to learn the ROOT directory of your Apache’s configuration files. In the command line, you can type:

In my case, my Apache’s ROOT configuration directory is shown in the

Now that I know the location of the configs that Apache is using, I can now accurately determine the version of PHP it is using by examining the «mods-enabled» directory located inside the «/etc/apache2» directory.

In my case, when do an ls while inside the «mods-enabled» , it showed the ff output:

At this point, I now know for certain that Apache is using the ‘php5’ version of PHP installed on my system, whatever that may be.

Then I tried to reproduce the error above using this version of PHP (i.e., ‘php5’ ) by running the command below:

The version of PHP that I expected my Apache was using is «php5.6» and running the same command above with this version did not produce the said error.

Solution

To solve this problem, you either install the version of the module that corresponds to the PHP version that Apache is using (in my example php5.0-curl) or you may change the version of PHP that is being used in Apache to the version you want.

How do I tell Apache which version of PHP to use?

You can accomplish this using the a2enmod/a2dismod cli commands of Apache2.

Firstly, I disable the PHP module that is currently active on my server (i.e., «php5» ):

Then I enabled the php module for the version of PHP that I want my Apache to use:

Then I restart Apache

After I refreshed the offending page on my website, the error is now gone.

Читайте также:  Что установить windows или mac os

Solved – Fatal error: Call to undefined function curl_init

This is a common error that occurs whenever PHP’s curl extension has not been installed or enabled.

The error will read something like this:

Fatal error: Call to undefined function curl_init()

Essentially, PHP can’t find the curl_init function because the extension that defines it has not been loaded. This results in a fatal error, which kills the PHP script.

To avoid this kind of error, you can check to see whether the cURL module has been loaded or not before you attempt to use it.

Check to see if curl is enabled.

To see if your PHP installation has curl enabled, you can run the following code:

The phpinfo function above will output information about PHP’s configuration.

If you do a CTRL + F search for curl and nothing is found, then it means that your PHP installation does not have curl enabled. If you do find it, then you should see the following line under the curl heading:

Note that you should NOT leave this phpinfo function on a live web server, as it outputs sensitive information about your PHP installation!

Enabling curl on Linux.

If your web server is running on Linux and you have SSH / terminal access, you can make sure that curl is installed by running the following command:

After running the command above, you will need to restart your web server so that the changes will take effect.

If you are using Apache, you can restart your web server like so:

If you are using Nginx, you can use the following command:

After your web server has been restarted, curl should be enabled.

Enabling curl on Windows.

If you are using Windows, you will need to locate the php.ini file that is being used by your web server. If you are unsure about which php.ini file you need to edit, then you can use the phpinfo script that we used above, as that will display the full path to the file that is being used by the web server.

Once you have located your php.ini file, you will need to “uncomment” the following line:

To uncomment the line above and enable the php_curl.dll extension, simply remove the semi-colon at the beginning.

After you have saved the changes that you made to your php.ini file, you will need to restart your web server. Otherwise, the new configuration will not take effect.

Enabling curl on WampServer.

If you are using the popular WampServer program on Windows, then you can try the following steps:

  1. Click on the WampServer icon in your system tray.
  2. Hover over the “PHP” option.
  3. Once the PHP menu appears, hover over the “PHP extensions” option.
  4. At this stage, a list of PHP extensions should appear. If an extension has a tick beside it, then it is already enabled. If the php_curl option does not have a tick beside it, then it is not enabled. To enable curl, simply click on the php_curl option.
  5. WampServer should automatically restart Apache and the changes should take effect.
  6. If WampServer does not automatically restart Apache, then you can manually force it to do so by clicking on the “Restart All Services” option in the main menu.

Hopefully, this guide helped you to get rid of that nasty “undefined function curl_init” error!

curl_init() function not working

Hi I tries PHP Post Request inside a POST Request thinking it might be useful to me and my code is given below

form the index.php file and index2.php is another file in the same directory and when i open the page i get the following error in my error.log file

Читайте также:  Где лежит ssh linux

What i want to do is I have a reservation form that send post request and then i want to process post values and send again post request to paypal

23 Answers 23

You need to install CURL support for php.

In Ubuntu you can install it via

If you’re using apt-get then you won’t need to edit any PHP configuration, but you will need to restart your Apache.

If you’re still getting issues, then try and use phpinfo() to make sure that CURL is listed as installed. (If it isn’t, then you may need to open another question, asking why your packages aren’t installing.)

There is an installation manual in the PHP CURL documentation.

$ sudo apt-get install php5_curl Reading package lists. Done Building dependency tree Reading state information. Done E: Couldn’t find package php5_curl – Santosh Linkha Dec 18 ’10 at 9:50

For Windows, if anybody is interested, uncomment the following line (by removing the 😉 from php.ini

Restart apache server.

I got it working in ubuntu 16.04 by following steps.My php version was 7.0

sudo service apache2 restart

For Ubuntu: add extension=php_curl.so to php.ini to enable, if necessary. Then sudo service apache2 restart

this is generally taken care of automatically, but there are situations — eg, in shared development environments — where it can become necessary to re-enable manually.

The thumbprint will match all three of these conditions:

  1. Fatal Error on curl_init() call
  2. in php_info, you will see the curl module author (indicating curl is installed and available)
  3. also in php_info, you will see no curl config block (indicating curl wasn’t loaded)

To fix this bug, I did:

  1. In php.ini file, uncomment this line: extension=php_curl.dll
  2. In php.ini file, uncomment this line: extension_dir = «ext»
  3. I restarted NETBEANS, as I was using Built-in server

In my case, in Xubuntu, I had to install libcurl3 libcurl3-dev libraries. With this command everything worked:

(remove the ; at the end of the line)

Add this to Apache/conf/httpd.conf (libeay32.dll, ssleay32.dll, libssh2.dll find directly in php7 folder)

I got this error using PHP7 / Apache 2.4 on a windows platform. curl_init worked from CLI but not with Apache 2.4. I resolved it by adding LoadFile directives for libeay32.dll and ssleay32.dll:

This answer is for https request:

Curl doesn’t have built-in root certificates (like most modern browser do). You need to explicitly point it to a cacert.pem file:

Without this, curl cannot verify the certificate sent back via ssl. This same root certificate file can be used every time you use SSL in curl.

Just adding my answer for the case where there are multiple versions of PHP installed in your system, and you are sure that you have already installed the php-curl package, and yet Apache is still giving you the same error.

(Trying to get Curl working via PHP and Apache on Windows. )

I kept getting an error saying: Call to undefined function ‘curl_init()’

I made sure I had enabled curl with this line in my php.ini file: extension=php_curl.dll

I made sure the extension_dir variable was being set properly, like this: extension_dir = «ext»

I was doing everything everyone else said on the forums and curl was not showing up in my call to phpinfo(), and I kept getting that same error from above.

Finally I found out that Apache by default looks for php.ini in the C:\Windows folder. I had been changing php.ini in my PHP installation folder. Once I copied my php.ini into C:\Windows, everything worked.

Took me forever to figure that out, so thought I’d post in case it helps someone else.

Оцените статью