program tip

curl_init () 함수가 작동하지 않습니다.

radiobox 2021. 1. 5. 07:54
반응형

curl_init () 함수가 작동하지 않습니다.


안녕하세요 저는 POST 요청 내에서 PHP Post Request를 시도합니다. 그것이 나에게 유용 할 것이라고 생각하고 내 코드는 아래에 나와 있습니다.

$sub_req_url = "http://localhost/index1.php";

$ch = curl_init($sub_req_url);
$encoded = '';

// include GET as well as POST variables; your needs may vary.
foreach($_GET as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}

foreach($_POST as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}

// chop off last ampersand
$encoded = substr($encoded, 0, strlen($encoded)-1);

curl_setopt($ch, CURLOPT_POSTFIELDS,  $encoded);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_exec($ch);
curl_close($ch);

index.php 파일을 형성하고 index2.php는 동일한 디렉토리에있는 다른 파일이며 페이지를 열면 내 error.log 파일에 다음 오류가 발생합니다.

[Sat Dec 18 15:24:53 2010] [error] [client ::1] PHP Fatal error:  Call to undefined function curl_init() in /var/www/testing1/index.php on line 5

내가 원하는 것은 포스트 요청을 보내는 예약 양식이 있고 포스트 값을 처리하고 다시 페이팔로 포스트 요청을 보내고 싶습니다.


PHP에 대한 CURL 지원을 설치해야합니다.

Ubuntu에서는 다음을 통해 설치할 수 있습니다.

sudo apt-get install php5-curl

apt-get을 사용하는 경우 PHP 구성을 편집 할 필요가 없지만 Apache를 다시 시작해야합니다.

sudo /etc/init.d/apache2 restart

여전히 문제가 발생하면 phpinfo () 를 사용하여 CURL이 설치된 것으로 표시되는지 확인하십시오. (그렇지 않은 경우 패키지가 설치되지 않는 이유를 묻는 다른 질문을 열어야 할 수 있습니다.)

PHP CURL 문서 에 설치 매뉴얼이 있습니다 .


Windows의 경우 관심이있는 사람이 있으면 php.ini에서 다음 줄의 주석 처리 (; 제거)를 제거하십시오.

;extension=php_curl.dll

아파치 서버를 다시 시작하십시오.


Ubuntu의 경우 : extension=php_curl.so필요한 경우 php.ini에 추가 하여 활성화합니다. 그때sudo service apache2 restart

이다 일반적으로 자동으로 알아서하지만, 상황이있다 - 예를 들어, 공유 개발 환경에서 - 그것은 수동으로 다시 활성화 할 필요가는.

지문은 다음 세 가지 조건 모두와 일치합니다.

  1. curl_init () 호출시 치명적인 오류
  2. php_info에서 curl 모듈 작성자를 볼 수 있습니다 (컬이 설치되어 사용 가능함을 나타냄).
  3. 또한 php_info에서 curl 구성 블록이 표시되지 않습니다 (컬이로드되지 않았 음을 나타냄).

다음 단계에 따라 우분투 16.04에서 작동합니다. 내 PHP 버전은 7.0이었습니다.

sudo apt-get install php7.0-curl

sudo 서비스 apache2 다시 시작

자세한 내용은 여기에서 확인하세요.


제 경우에는 Xubuntu에서 libcurl3 libcurl3-dev 라이브러리를 설치해야했습니다. 이 명령으로 모든 것이 작동했습니다.

sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

1 단계 :

C:/(path to php folder)/php.ini
enable extension=php_curl.dll

( ;줄 끝에서 제거 )

2 단계 :

이것을 Apache/conf/httpd.conf(libeay32.dll, ssleay32.dll, libssh2.dll은 php7 폴더에서 직접 찾습니다)에 추가하십시오.

# load curl and open ssl libraries
 LoadFile "C:/(path to php folder)/libeay32.dll"
 LoadFile "C:/(path to php folder)/ssleay32.dll"
 LoadFile "C:/(path to php folder)/libssh2.dll"

이 버그를 수정하기 위해 다음을 수행했습니다.

  1. 에서 php.ini파일이 행의 주석 :extension=php_curl.dll
  2. 에서 php.ini파일이 행의 주석 :extension_dir = "ext"
  3. 내장 서버를 사용하고 있었기 때문에 NETBEANS를 다시 시작했습니다.

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:

LoadFile "C:/path/to/Php7/libeay32.dll"
LoadFile "C:/path/to/Php7/ssleay32.dll"
LoadFile "C:/path/to/Php7/php7ts.dll"
LoadModule php7_module "C:/path/to/Php7/php7apache2_4.dll"

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.

curl_init() undefined even if php-curl is enabled in Php 7.


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:

  curl_setopt($ch, CURLOPT_CAINFO, '/path/to/cert/file/cacert.pem');

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.

You can get the cacert.pem file here: http://curl.haxx.se/docs/caextract.html

Reference PHP cURL Not Working with HTTPS


Had this problem but found the answer here: https://askubuntu.com/questions/1116448/cannot-enable-php-curl-on-ubuntu-18-04-php-7-2

Had to:

sudo a2dismod php7.0

And:

sudo a2enmod php7.2

Then:

sudo service apache2 restart

This was after a system upgrade to next version of Ubuntu. All the other answers I found were stale, due to a bad cert apparently on the PPA most of them pointed out, but would probably not have worked anyway. The real issue was disabling the old versions of php, apparently.

Found the solution here:

https://askubuntu.com/questions/1116448/cannot-enable-php-curl-on-ubuntu-18-04-php-7-2


Seems you haven't installed the Curl on your server.
Check the PHP version of your server and run the following command to install the curl.

sudo apt-get install php7.2-curl

Then restart the apache service by using the following command.

sudo service apache2 restart

Replace 7.2 with your PHP version.


(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.


RusAlex answer is right in that for Apache you have to install and enable curl and restart your apache service:

sudo apt-get install php5-curl
sudo service apache2 restart

On my Ubuntu Server with nginx and php5-fpm I however ran into the following problem. I had to restart nginx and php5-fpm like so:

sudo service nginx restart
sudo service php5-fpm restart

But I had non-working php5-fpm processes hanging around, which apparently is a bug in ubuntu https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1242376 So I had to kill all idle php5-fpm processes to able to restart php5-fpm so that the curl module is actually loaded

sudo kill <Process Id of php5-fpm Process)

function curl_int(); cause server error,install sudo apt-get install php5-curl restart apache2 server .. it will work like charm


For PHP 7 and Windows x64

libeay32.dll, libssh2.dll and ssleay32.dll should not be in apache/bin and should only exist in php directory and add php directory in system environment variable. This work for me.

Obvisouly in php.ini you should have enable php_curl.dll as well.


For linux you can install it via

sudo apt-get install php5-curl

For Windows(removing the ;) from php.ini

;extension=php_curl.dll

Restart apache server.


On Ubuntu 18.04 these two commands solve my this problem.

sudo apt-get install php5.6-curl //install curl for php 5.6
sudo service apache2 restart //restart apache

ReferenceURL : https://stackoverflow.com/questions/4477535/curl-init-function-not-working

반응형