12

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.

ignite-me
  • 738
  • 3
  • 14
  • 33
  • See [How to upgrade OpenSSL in OS X?](http://apple.stackexchange.com/q/126830) on the Apple Stack Exchange or [Compilation and Installation](https://wiki.openssl.org/index.php/Compilation_and_Installation) on the OpenSSL wiki. – jww Feb 04 '17 at 23:09
  • These may apply as well, if you have already installed OpenSSL: [How do I install pyOpenSSL on Mac OS X?](http://stackoverflow.com/q/14361569), [Updating openssl in python 2.7](http://stackoverflow.com/q/18752409), [Python referencing old SSL version](http://stackoverflow.com/q/24323858), [Python and OpenSSL version reference issue on OS X](http://stackoverflow.com/q/37690054), [Python 3.3 and Installing PyOpenSSL on a Mac](http://stackoverflow.com/q/21899573), [Using Python with homebrew on OS X](http://stackoverflow.com/q/25441252), etc... – jww Feb 04 '17 at 23:10
  • How are you trying to install this driver? – miken32 Mar 20 '17 at 04:18

4 Answers4

20

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/

5ive
  • 273
  • 2
  • 11
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
sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
  • 1
    OpenSSL is already installed, it just cannot be found by the installed package for some reason. – ignite-me Feb 04 '17 at 22:02
  • 1
    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 05 '17 at 01:35
  • 2
    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"` –  Mar 13 '18 at 17:46
  • 1
    As @sideshowbarker said, maybe you need to run the `brew install openssl` command anyway. Then, since OpenSSL is keg-only, it has to be referred from an environment variable (I.e., the `bin` folder of installation directory should be added to the system `PATH` variable - It may be a bit different in your system, it’s because it depends on its version.). Here is a valuable article about this: [Installing OpenSSL library on macOS Catalina](https://yasar-yy.medium.com/installing-openssl-library-on-macos-catalina-6777a2e238a6) – YUSMLE Jul 10 '23 at 16:41
4

First install libressl using brew:

brew install libressl

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"
Farshid Ashouri
  • 16,143
  • 7
  • 52
  • 66
1

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

Myles
  • 454
  • 1
  • 6
  • 12