Sunday, September 4, 2022

[SOLVED] How to get PHP 8.1 to recognize curl_init?

Issue

I know this may seem similar to many questions already out there, but I've read dozens and I am still experiencing the same issue. My code works fine on my local machine, and my Raspberry Pi was configured by the exact same setup script, but it doesn't work on the Pi.

My OS is Raspbian 10 (Buster) with kernel version 5.10.103-v7l+. I am running PHP 8.1, along with the other packages in the following command: sudo apt install -y php8.1-common php8.1-cli php8.1-fpm php8.1-xml php8.1-curl

php -m lists curl and php -i and phpinfo() show that cURL is installed and enabled:

cURL support => enabled
cURL Information => 7.64.0

I know cURL is installed and enabled, so how do I get my PHP to recognize and use the package? It works perfectly on my local Linux box but on the Pi it just doesn't. I have restarted my server and my entire machine and neither made a difference. I have ran sudo apt update && sudo apt upgrade and everything is at the most recent version.

The 'problematic' snippet of code on my server is the following:

require "vendor/autoload.php";
use Symfony\Component\Panther\Client;

$options = [
        "--headless",
        "--window-size=1200,1100",
        "--no-sandbox",
        "--disable-gpu",
        "--disable-dev-shm-usage",
];

$query = urlencode($_GET["q"]);
$url ="/search?hl=en&tbo=d&site=&source=hp&q=".$query;
$client = Client::createChromeClient("/usr/lib/chromium-browser/chromedriver", $options, [], "http://www.google.com");
$client->request("GET", $url);

My full error log is:

*168 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function Facebook\WebDriver\Remote\curl_init() in /var/lib/jenkins/workspace/url-here.com/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:190
Stack trace:
#0 /var/lib/jenkins/workspace/url-here.com/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php(100): Facebook\WebDriver\Remote\HttpCommandExecutor->__construct()
#1 /var/lib/jenkins/workspace/url-here.com/vendor/symfony/panther/src/ProcessManager/ChromeManager.php(75): Facebook\WebDriver\Remote\RemoteWebDriver::create()
#2 /var/lib/jenkins/workspace/url-here.com/vendor/symfony/panther/src/Client.php(117): Symfony\Component\Panther\ProcessManager\ChromeManager->start()
#3 /var/lib/jenkins/workspace/url-here.com/vendor/symfony/panther/src/Client.php(521): Symfony\Component\Panther\Client->start()
#4 /var/lib/jenkins/workspace/url-here.com/vendor/symfony/panther/src/Client.php(273): Symfony\Component\Panther\Client->get()
#5 /var/lib/jenkins/workspace" while reading response header from upstream, client: 96.244.127.121, server: url-here.com, request: "GET /googleSearch.php?q=test HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.0-fpm.sock:", host: "url-here.com", referrer: "https://url-here.com/apps/browser.html"

Any and all help would be appreciated, I've been struggling with this one for a while. I would just avoid using curl_init() if I could, but unfortunately as you can see the function is called in a library that my project depends on.


Solution

This line from the error log indicates what the problem most likely is:

#5 /var/lib/jenkins/workspace" while reading response header from upstream, client: 96.244.127.121, server: url-here.com, request: "GET /googleSearch.php?q=test HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.0-fpm.sock:", host: "url-here.com", referrer: "https://url-here.com/apps/browser.html"

You've got PHP 8.0 here, but you've installed Curl for PHP 8.1. You need to check your FPM or server configuration.

I think you're using Nginx. If that's correct then this article might be helpful. Specifically you'll want to look in:

  • /etc/nginx/sites-available to check which socket is used
  • /etc/php/VERSION/fpm/pool.d to check what sockets are available


Answered By - RafaƂ G.
Answer Checked By - Candace Johnson (WPSolving Volunteer)