Matthew Groves
Matthew Groves

Reputation: 26169

Installing a PHP extension on Windows 10

I've been away from PHP for a while. Right now, I have a working CakePHP 3.x site running on IIS. Now, I need to install and use an extension (specifically a Couchbase extension, but I don't think my problem is Couchbase specific).

I've downloaded the DLL from PECL (here, the 5.6 Thread Safe 32bit download, specifically)

I think that I have to put the files in that zip file somewhere, and then I have to make a change to php.ini under ExtensionList. But I'm not sure where to put the files specifically, or which DLLs to reference.

I tried putting them in C:\Program Files (x86)\PHP\v5.6\ext\couchbase and then I added extension=couchbase/php_couchbase.dll to php.ini, restarted IIS. Then, I wrote this simple CakePHP controller just to make sure that worked:

<?php

namespace App\Controller;

class ProfilesController extends AppController
{
    public function index()
    {
        $cluster = new CouchbaseCluster("couchbase://127.0.0.1");
        $bucket = $cluster->openBucket("sqltocb");

        $query = CouchbaseN1qlQuery::fromString("SELECT b.* FROM `sqltocb` b LIMIT 10;");
        $query->consistency(CouchbaseN1qlQuery::REQUEST_PLUS);
        $result = $bucket->query($query);
        echo json_encode($result->rows);
    }
}

?>

But I get an error Error: Class 'App\Controller\CouchbaseCluster' not found, which I assume to mean that I didn't install the extension correctly. Any idea what I'm doing wrong?

Upvotes: 0

Views: 3673

Answers (1)

avsej
avsej

Reputation: 3972

My system version

PS> [Environment]::OSVersion

Platform ServicePack Version      VersionString
-------- ----------- -------      -------------
 Win32NT             10.0.14393.0 Microsoft Windows NT 10.0.14393.0

Download and extract PHP interpreter and the Couchbase extension:

PS> Invoke-WebRequest -Uri "http://windows.php.net/downloads/releases/php-5.6.31-Win32-VC11-x86.zip" -OutFile "php-5.6.31-Win32-VC11-x86.zip"
PS> Expand-Archive "php-5.6.31-Win32-VC11-x86.zip" -DestinationPath "C:\php"
PS> Invoke-WebRequest -Uri "http://packages.couchbase.com/clients/php/php_couchbase-2.3.4-5.6-zts-vc11-x86.zip" -OutFile "php_couchbase-2.3.4-5.6-zts-vc11-x86.zip"
PS> Expand-Archive "php_couchbase-2.3.4-5.6-zts-vc11-x86.zip" -DestinationPath "C:\php\ext"

Copy libcouchbase.dll to the place where your SAPI lives (in our case SAPI is PHP CLI, so we copy it into the same directory, where php.exe located):

PS> copy "C:\php\ext\libcouchbase.dll" "C:\php\libcouchbase.dll"

Update configuration:

PS> copy "C:\php\php.ini-development" "C:\php\php.ini"
PS> "extension=php_couchbase.dll" | Add-Content "C:\php\php.ini"

Lets check setup:

PS> C:\php\php.exe -i 2>$null | findstr -i couchbase
couchbase
couchbase support => enabled
libcouchbase runtime version => 2.7.6 (git: e15b267765913f110fd1bbf65749c54b56875ebf)
libcouchbase headers version => 2.7.6 (git: e15b267765913f110fd1bbf65749c54b56875ebf)
igbinary transcoder => disabled (install pecl/igbinary and rebuild pecl/couchbase)
couchbase.decoder.json_arrays => 0 => 0
couchbase.encoder.compression => off => off
couchbase.encoder.compression_factor => 0.0 => 0.0
couchbase.encoder.compression_threshold => 0 => 0
couchbase.encoder.format => json => json
couchbase.log_level => WARN => WARN

If you are using something different instead of C:\php, then make sure your extension directory match to place where PHP is looking for extensions, because this is is what it outputs by default (and php.ini-development does not override it):

PS> C:\php\php.exe  -i 2>$null | findstr -i extension_dir
extension_dir => C:\php\ext => C:\php\ext

All snippets executed in home directory using PowerShell, and PS> means its prompt.

Upvotes: 1

Related Questions