Search code examples
phpphp-extension

How to add PHP extension in Windows 10?


I have downloaded PHP build from Chocolatey on my Windows 10 PC. I have attempted to install and activate the PHP Redis extension, so I downloaded the archive, copied the php_redis.dll extension file to the default ext folder and modified the php.ini file like so:

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;

; If you wish to have an extension loaded automatically, use the following
; syntax:
;
;   extension=modulename
;
; For example:
;
;   extension=mysqli
;
; When the extension library to load is not located in the default extension
; directory, You may specify an absolute path to the library file:
;
;   extension=/path/to/extension/mysqli.so
;
; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
; 'extension='php_<ext>.dll') is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new ('extension=<ext>) syntax.
;
; Notes for Windows environments :
;
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
;   extension folders as well as the separate PECL DLL download (PHP 5+).
;   Be sure to appropriately set the extension_dir directive.
;
extension=bz2
extension=curl
extension=ffi
extension=ftp
extension=fileinfo
extension=gd2
extension=gettext
extension=gmp
extension=intl
extension=imap
extension=ldap
extension=mbstring
extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
extension=odbc
extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
extension=pgsql
extension=shmop

; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
;extension=snmp

extension=soap
extension=sockets
extension=sodium
extension=sqlite3
extension=tidy
extension=xmlrpc
extension=xsl

; Added by Rumon:
extension=mongodb
extension=redis

Followed this same path to install mongodb extension as well (Downloaded from here).

Now, when I do anything related to those drivers, I get error that the system cannot find the extensions. For example:

$ php --ini
PHP Warning:  PHP Startup: Unable to load dynamic library 'mongodb' (tried: ext\mongodb (The specified module could not be found.), ext\php_mongodb.dll (The specified module could not be found.)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'redis' (tried: ext\redis (The specified module could not be found.), ext\php_redis.dll (The specified module could not be found.)) in Unknown on line 0
Configuration File (php.ini) Path:
Loaded Configuration File:         C:\tools\php74\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

For everybody's convenience, I am providing a SS of the extensions directory, have a look.

Can anyone explain what's causing the issue? And how can I resolve this?


Solution

  • After researching for a while, I found that "Thread Safety" is a THING in PHP world! I wrongly installed the TS version, while I was needed the NTS version.

    To everyone: When you try to install any PHP extension, check your system and make sure that you download the appropriate (TS/NTS) version.

    Cheers!