Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloud9 cURL not working

I was just fiddling with php on cloud9 the other day and I can upon this problem that cURL did not seem to be working. When you make a php workspace in cloud9, there is autocomplete for cURL so they must 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 a 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 with my code or a problem with cloud9. Thank you!

like image 462
Holger Kibur Avatar asked Feb 22 '26 14:02

Holger Kibur


1 Answers

Open a terminal in your cloud 9 enviroment:

First make sure you are running as the master user run 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 issues.

like image 93
vikingben Avatar answered Feb 24 '26 04:02

vikingben