Php – Why do the two live servers not run this curl command, but the local test server does

curlPHP

I have three servers. Two are live servers hosting web sites for the internet. One is a local testing server, not visible on the internet at larger.

I am trying to run a PHP script that posts to Twitter, and it relies on curl. When I run the script on my local testing machine, it works perfectly. When I try and run it on either of my live servers, it fails with this error:

PHP Fatal error: Call to undefined function Abraham\TwitterOAuth\curl_init()

On my local machine, when I run php --info | grep -i curl, I get this response:

/etc/php5/cli/conf.d/20-curl.ini,
curl
cURL support => enabled
cURL Information => 7.35.0

I only have SSH access to one of my live servers (the other is a paid hosting service that is more restricted), and when I run the same command on that server, I get no response. The command prompt comes back with nothing. However, if I go to the /etc/php5/cli/conf.d/ directory on my live server, there is a 20-curl.ini file there.

All servers are Ubuntu based, and I've run apt-get install php5-curl curl on all of them, and they all say they are running the latest version.

Here's the last confusing detail, on all servers, if I run this PHP script on any of my servers, my local test server and both live servers, I get a positive response. This is the code:

echo 'Curl: ', function_exists('curl_init') ? 'Enabled' : 'Disabled';

… and when I run it, I get this output:

Curl: Enabled

Bottom line, it seems curl is installed on all three servers, but something is wrong with the installation on both of my live servers.

What can I do to diagnose and solve why my live servers can't run the PHP script that my local test server can?

Best Answer

You are most likely missing this library on the server: https://github.com/abraham/twitteroauth

The PHP error shows that it is trying to load a function from TwitterOAuth, and it doesn't work because the library is missing.

Another possibility is that your script contains some kind of autoloader library, which doesn't work correctly on your live server environment (looks up the library in wrong path).