Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

See How to upgrade OpenSSL in OS X? on the Apple Stack Exchange or Compilation and Installation on the OpenSSL wiki. – jww Feb 4, 2017 at 23:09 These may apply as well, if you have already installed OpenSSL: How do I install pyOpenSSL on Mac OS X?, Updating openssl in python 2.7, Python referencing old SSL version, Python and OpenSSL version reference issue on OS X, Python 3.3 and Installing PyOpenSSL on a Mac, Using Python with homebrew on OS X, etc... – jww Feb 4, 2017 at 23:10

You’ll need to install OpenSSL using homebrew, and tell homebrew to create 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
                OpenSSL is already installed, it just cannot be found by the installed package for some reason.
– ignite-me
                Feb 4, 2017 at 22:02
                When you say it’s already installed, do you mean you installed it with homebrew? Because if it‘s not the version installed with homebrew, I think you may not have the necessary header files installed. (Even if you the have OpenSSL binaries installed, that doesn’t necessarily mean you’ll have the header files; you need to ensure that OpenSSL is installed in a way that also installs the header files.)
– sideshowbarker
                Feb 5, 2017 at 1:35
                Don't forget to set your environment variables export LDFLAGS="-L/usr/local/opt/openssl/lib -L/usr/local/lib -L/usr/local/opt/expat/lib" && export CFLAGS="-I/usr/local/opt/openssl/include/ -I/usr/local/include -I/usr/local/opt/expat/include" && export CPPFLAGS="-I/usr/local/opt/openssl/include/ -I/usr/local/include -I/usr/local/opt/expat/include"
– user8389458
                Mar 13, 2018 at 17:46

Then run the following:

export LDFLAGS="-L/usr/local/opt/openssl/lib -L/usr/local/lib \
-L/usr/local/opt/expat/lib" && export CFLAGS="-I/usr/local/opt/openssl/include/ \
-I/usr/local/include -I/usr/local/opt/expat/include" && export \
CPPFLAGS="-I/usr/local/opt/openssl/include/ -I/usr/local/include \
-I/usr/local/opt/expat/include"

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

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.