PHP code works in command line but not in browser

I’m using this code to connect to Couchbase Server and query a view:

$myCluster = new CouchbaseCluster('couchbase://127.0.0.1');
$myBucket = $myCluster->openBucket('devbucket');
$query = CouchbaseViewQuery::from('dev_pole', 'poleView');
$res = $myBucket->query($query);
var_dump($res);

The php file is parsed fine in command line and output the desired result, but when using the browser nothing shows not even an error. looked at the php error log file, here is the error when page loads in the browser:

PHP Fatal error:  Class 'CouchbaseCluster' not found in /var/www/public/poles.php on line 12

Hey hsharghi,

This indicates that you have not installed the extension properly. Please make sure you have added the extension=couchbase.so line to your php.ini!

Cheers, Brett

Yes, keep in mind that CLI and Web server are two different ways to access PHP and can be configured differently. One example would be that two different php.ini’s are used or even different PHP versions installed.

1 Like

Thanks, that was the problem. The extension had been added to /etc/php5/cli/php.ini and now I added to /etc/php5/apache2/php.ini and everything is working fine.

1 Like