Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing curl to PHP cli

I'm trying to set up a cronjob which requires curl, and I'm calling it directly from crontab with

* * * * * /usr/bin/php myurl/my_cron.php

The problem is, it looks like the curl module isn't installed for my phpcli.

It works just fine when I hit the url from my browser, but when I run

php -q myfile.php

from the command line, it returns

PHP Fatal error:  Call to undefined function curl_init() in my_cron.php on line 20

When I run php -m the curl module does not show up. However when I go to the browser and dump the php_info(), the module shows up and says its correctly installed.

The other kicker is i've been trying to install curl with apt-get onto the server (Ubuntu 12.04 php 5.4), it seems to take down my PHP as it begins to simply attempt to download the index.php file wherever I try to browse to.

Here are the attempts I've made to install curl that have taken down PHP:

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

After each of these I restarted the apache2 server and still no dice, it attempted to download the file instead of opening the page.

How can I install php5-curl to just the cli, so that my server can run it and I don't have to go through a browser?

The other possibility is I could run the cronjobs through wget from the crontab file, but I've heard that's not the best option and potentially unreliable.

Any help is much appreciated. Thanks!

like image 799
user2966822 Avatar asked Nov 07 '13 22:11

user2966822


1 Answers

I had the same issue. But, finally I solved it by running the following command.

sudo apt-get install php7.0-curl

Restart the server after installing. This answer may not be useful for the user who asked because he asked it two months ago. But, this may be useful for the users who reading this in the future.

like image 163
Sriraman Avatar answered Sep 21 '22 22:09

Sriraman