Fatal error: 'openssl/ssl.h' file not found on macos

Following the PHP Driver documentation to install mongodb driver for PHP on this link:

My environment:

Device: MacBook Pro M1 Chip
OS: Sequoia 15.3.2
PHP Version: 8.2.4

When running the following command:

pie install mongodb/mongodb-extension

I am getting fatal error: ‘openssl/ssl.h’ file not found

make: *** [src/libmongoc/src/libmongoc/src/mongoc/mongoc-bulk-operation.lo] Error 1                                                                                             
  In file included from /Users/<username>/.pie/php8.2_b160a39733268fdabf3b4426e220eb7d/vendor/mongodb/mongodb-extension/mongodb-2.1.1/src/libmongoc/src/libmongoc/src/mongoc/mongo  
  c-bulkwrite.c:24:                                                                                                                                                               
  In file included from /Users/<username>/.pie/php8.2_b160a39733268fdabf3b4426e220eb7d/vendor/mongodb/mongodb-extension/mongodb-2.1.1/src/libmongoc/src/libmongoc/src/mongoc/mongo  
  c-client-private.h:27:                                                                                                                                                          
  In file included from /Users/<username>/.pie/php8.2_b160a39733268fdabf3b4426e220eb7d/vendor/mongodb/mongodb-extension/mongodb-2.1.1/src/libmongoc/src/libmongoc/src/mongoc/mongo  
  c-cluster-private.h:35:                                                                                                                                                         
  In file included from /Users/<username>/.pie/php8.2_b160a39733268fdabf3b4426e220eb7d/vendor/mongodb/mongodb-extension/mongodb-2.1.1/src/libmongoc/src/libmongoc/src/mongoc/mongo  
  c-topology-private.h:23:                                                                                                                                                        
  /Users/<username>/.pie/php8.2_b160a39733268fdabf3b4426e220eb7d/vendor/mongodb/mongodb-extension/mongodb-2.1.1/src/libmongoc/src/libmongoc/src/mongoc/mongoc-topology-scanner-pri  
  vate.h:26:10: fatal error: 'openssl/ssl.h' file not found                                                                                                                       
     26 | #include <openssl/ssl.h>                                                                                                                                                
        |          ^~~~~~~~~~~~~~~                                                                                                                                                
  1 error generated.                                                                                                                                                              
  make: *** [src/libmongoc/src/libmongoc/src/mongoc/mongoc-bulkwrite.lo] Error 1                                                                                                  
  In file included from /Users/<username>/.pie/php8.2_b160a39733268fdabf3b4426e220eb7d/vendor/mongodb/mongodb-extension/mongodb-2.1.1/src/libmongoc/src/libmongoc/src/mongoc/mongo  
  c-change-stream.c:18:                                                                                                                                                           
  In file included from /Users/<username>/.pie/php8.2_b160a39733268fdabf3b4426e220eb7d/vendor/mongodb/mongodb-extension/mongodb-2.1.1/src/libmongoc/src/libmongoc/src/mongoc/mongo  
  c-cluster-private.h:35:                                                                                                                                                         
  In file included from /Users/<username>/.pie/php8.2_b160a39733268fdabf3b4426e220eb7d/vendor/mongodb/mongodb-extension/mongodb-2.1.1/src/libmongoc/src/libmongoc/src/mongoc/mongo  
  c-topology-private.h:23:                                                                                                                                                        
  /Users/<username>/.pie/php8.2_b160a39733268fdabf3b4426e220eb7d/vendor/mongodb/mongodb-extension/mongodb-2.1.1/src/libmongoc/src/libmongoc/src/mongoc/mongoc-topology-scanner-pri  
  vate.h:26:10: fatal error: 'openssl/ssl.h' file not found                                                                                                                       
     26 | #include <openssl/ssl.h>                                                                                                                                                
        |          ^~~~~~~~~~~~~~~                                                                                                                                                
  1 error generated.                                                                                                                                                              
  make: *** [src/libmongoc/src/libmongoc/src/mongoc/mongoc-change-stream.lo] Error 1

Can’t install PHP mongodb driver successfully on MacOS with M1 Chip

Do you happen to have the full log for the install? I’m interested in the output from configure, which should look something like this:

mongodb was configured with the following options:

Build configuration:
  CC                                               : cc
  CFLAGS                                           : -g -O2 -O0
  CPPFLAGS                                         :  -DHAVE_CONFIG_H
  Extra flags                                      : -g -O0 -Wall
  Developer flags (slow)                           :  -Wmissing-format-attribute -Wduplicate-enum -Wheader-guard -Wlogical-not-parentheses -fno-omit-frame-pointer -fno-optimize-sibling-calls -Wlogical-op-parentheses -Wpointer-bool-conversion -Wbool-conversion -Wloop-analysis -Wsizeof-array-argument -Wstring-conversion -Wno-variadic-macros -Wno-sign-compare -fstack-protector -fno-exceptions -Wformat-security -Wformat-nonliteral -Winit-self -Wwrite-strings -Wenum-compare -Wempty-body -Wparentheses -Wimplicit-fallthrough -Werror -Wextra -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-missing-field-initializers -Wno-deprecated-declarations -Wstrict-prototypes
  Code Coverage flags (extra slow)                 : 
  libmongoc                                        : Bundled (2.0.2)
  libbson                                          : Bundled (2.0.2)
  libmongocrypt                                    : Bundled (1.14.1)
  LDFLAGS                                          : 
  EXTRA_LDFLAGS                                    : 
  MONGODB_SHARED_LIBADD                            : -Wl,-rpath,/opt/homebrew/Cellar/openssl@3/3.5.0/lib -L/opt/homebrew/Cellar/openssl@3/3.5.0/lib -lsasl2 -lresolv -Wl,-rpath,/opt/homebrew/opt/zstd/lib -L/opt/homebrew/opt/zstd/lib  -lpthread -pthread -lz -lzstd -lssl -lcrypto -lpthread -pthread

From what it looks like, the configure script detected or was instructed to use OpenSSL, but the headers couldn’t be found. Did you install openssl using brew at all?

Here is the log:

mongodb was configured with the following options:

Build configuration:
CC : cc
CFLAGS : -g -O2
CPPFLAGS : -DHAVE_CONFIG_H
Extra flags :
Developer flags (slow) :
Code Coverage flags (extra slow) :
libmongoc : Bundled (1.30.5)
libbson : Bundled (1.30.5)
libmongocrypt : Bundled (1.12.0)
LDFLAGS :
EXTRA_LDFLAGS :
MONGODB_SHARED_LIBADD : -Wl,-rpath,/lib -L/lib -lsasl2 -lresolv -Wl,-rpath,/lib -L/lib -lpthread -pthread -lz -lssl -lcrypto -lpthread -pthread

I have openssl installed through homebrew

Ok, so the CheckSSL script is definitely not finding openssl. The extensions requires a version newer than 1.0.1, but since brew only ships OpenSSL 1.1 and 3.x I think we can rule out an older version. Can you confirm which version of OpenSSL is installed?

One reason why we may fail to find OpenSSL could be that pkg-config is missing. Could you please check if the pkgconf brew package is installed? You can do so by running brew list | grep pkgconf. If it’s not listed, please install it and try again. If this turns out to be the cause, I can then see what we can improve on detecting OpenSSL installed through brew; I’d hate to hardcode a path.

I have openssl version 1.1.1 installed

pkgconf is installed as well

See image below

I have just looked up the location of openssl:

command: which openssl

output: /Applications/XAMPP/xamppfiles/bin/openssl

To confirm that i do have openssl installed through brew as well

command: brew list | grep openssl
output: openssl@3

So could it be that openssl in XAMPP is interfering with the installation?

I have been able to resolve the issue by removing /Applications/XAMPP/xamppfiles/bin/openssl from the path. Its now showing openssl installed through Homebrew.

mongodb was configured with the following options:

Build configuration:
CC : cc
CFLAGS : -g -O2
CPPFLAGS : -DHAVE_CONFIG_H
Extra flags :
Developer flags (slow) :
Code Coverage flags (extra slow) :
libmongoc : Bundled (1.30.5)
libbson : Bundled (1.30.5)
libmongocrypt : Bundled (1.12.0)
LDFLAGS :
EXTRA_LDFLAGS :
MONGODB_SHARED_LIBADD : -Wl,-rpath,/opt/homebrew/Cellar/openssl@3/3.5.1/lib -L/opt/homebrew/Cellar/openssl@3/3.5.1/lib -lsasl2 -lresolv -Wl,-rpath,/opt/homebrew/opt/zstd/lib -L/opt/homebrew/opt/zstd/lib -lpthread -pthread -lz -lzstd -lssl -lcrypto -lpthread -pthread

Thanks for support

Glad you got it fixed, and thanks for sharing the solution!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.