Cloud9 cURL not working

The other day I was just playing with php on cloud9 and I can on this issue that cURL doesn't seem to work. When you create a php workspace in cloud9 there is autocomplete for cURL to let them know about it. Here is the code:

<?php
function file_get_data($url){
$ch = curl_init();
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4                      KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4');
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$data=curl_exec($ch);
curl_close($ch);
return $data;
}
$raw=file_get_data('https://github.com/bower/json/blob/master/package.json') or      die('Error Connecting to Resource');
$data=json_decode($raw,true);
echo $data['name'];
?>

      

The error I am getting in bash is:

Fatal error: Call to undefined function curl_init() in /home/ubuntu/workspace/a.php on line 3

      

I don't know if this is a problem for my code or a cloud problem9. Thank!

+3


source to share


2 answers


Open a terminal in cloud 9:

First make sure you run when the main user runs this command:

sudo bash



Then run this command to install cURL from command.

apt-get install php5-curl

Then curl_init () should be recognized without issue.

+5


source


Your php installation doesn't have cURL support. You need to compile php --with-curl=[DIR]

.



- http://php.net/manual/en/curl.installation.php

0


source







All Articles