OpenSSL not found on MacOS Sierra

2020-06-03 08:09发布

问题:

I am trying to install a PHP MongoDB driver but the installation is failing because it cannot locate the OpenSSL.

/Users/username/mongo-php-driver/src/libmongoc/src/mongoc/mongoc-crypto-openssl.c:24:10: fatal error: 'openssl/sha.h' file not found
#include <openssl/sha.h>
         ^
1 error generated.
make: *** [src/libmongoc/src/mongoc/mongoc-crypto-openssl.lo] Error 1

I read that this has something to do with the latest version of MacOS? Is there a way to do it, as I really need to install this driver.

回答1:

This is the only solution that worked for me.

cd /usr/local/include 
ln -s ../opt/openssl/include/openssl .

Source: https://www.anintegratedworld.com/mac-osx-fatal-error-opensslsha-h-file-not-found/



回答2:

You’ll need to install OpenSSL using homebrew, and tell homebrew to create necessary symlinks:

brew install openssl
brew link openssl --force

If you don’t already have homebrew installed, you can get it by running this:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

And before all that, if you haven’t already installed XCode and the XCode command-line tools:

xcode-select --install


回答3:

You can use environment variable C_INCLUDE_PATH to tell the compiler to include the path to openssl header files.

For example, if you just want to do it once:

sudo C_INCLUDE_PATH=/usr/local/opt/openssl/include pecl install mongo


Reference: charles.lescampeurs.org