mongo-php-driver: Unable to Compile Driver for XAMPP on macOS
PHP XAMPP 7.2.7 on mac high sierra
Show this error when running make all
tmp/mongo-php-driver/src/libmongoc/src/libmongoc/src/mongoc/mongoc-scram.c:85:10: fatal error:
'unicode/usprep.h' file not found
#include <unicode/usprep.h>
^~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [src/libmongoc/src/libmongoc/src/mongoc/mongoc-scram.lo] Error 1
It also happen when using PECL
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 18 (8 by maintainers)
I started with a new macOS installation of High Sierra (version 10.13.6) and downloaded xampp-osx-7.2.7-0-r01-installer.dmg. Following the default installation process, XAMPP was installed to
/Applications/XAMPP. The XAMPP manager app was opened after the installation completed and “Manage Servers” showed that “Apache Web Server” running (“MySQL Database” and “ProFTPD” were stopped). The installer also opened Safari tohttp://mongodbs-mackbook-pro.local/dashboard, which I left open to return to later.I opened a terminal and attempting to install with the MongoDB driver with
/Applications/XAMPP/bin/pecl install mongodb:I attempted to update channels:
I attempted to update the temp dir:
Another attempt to update channels:
At this point, I decided to use
sudoto update channels and install the driver:Attempting to install again:
Attempting to list packages:
At this point, I gather that there may be some incompatibility between the build of PHP included with XAMPP and the OpenSSL library on macOS High Sierra. I’ll note the version of OpenSSL that PHP was compiled against and the version of OpenSSL available on macOS:
I decide to manually download the PECL package (mongodb-1.5.1.tgz) and install it from the local filesystem to bypass this SSL issue.
I install Homebrew and proceed to install the following packages:
I then repeat installation of the extension, which ultimately fails for the same reason cited in your original comment, which was failure to include
unicode/usprep.h. I notice that theconfigureoutput when I attempted to install the driver also includes the following suspect lines that you shared:Googling for
BITROCK_COMMON_ROOTDIRdid not turn up much, but “bitrock” comes up as the developer of Bitnami, which is affiliated with XAMPP. I also think it’s suspect that XAMPP is providing its own copy ofpkg-config, which reports@@BITROCK_COMMON_ROOTDIR@@in its include path (as you shared in https://github.com/mongodb/mongo-php-driver/issues/883#issuecomment-406140279). Since macOS High Sierra does not appear to ship withpkg-config, I decide to install it via Homebrew:If you run
configure --helpfor the extension, it reports that thePKG_CONFIGenvironment variable may be assigned the “path to pkg-config utility”. That is extracted fromscripts/autotools/m4/pkg.m4, which is the build script responsible for findingpkg-configand using it to check for dependencies. That said, I was not successful attempting to get XAMPP’speclcommand to respect my customizedPKG_CONFIGenvironment variable. I decided to look into how thepeclcommand was picking up/Applications/XAMPP/xamppfiles/bin/and found that it is assigned to thebin_dirPEAR configuration option.Since this is the same directory that contains other essential binaries (e.g.
phpize), I don’t think we can alter it without introducing a new problem. I think the best solution is to override/Applications/XAMPP/xamppfiles/bin/pkg-configwith a symlink to version installed by Homebrew.Let’s repeat the install process:
The
configurescript still picks up/Applications/XAMPP/xamppfiles/bin/pkg-configas expected, but that is now a symlink to Homebrew’spkg-configbinary. The@@BITROCK_COMMON_ROOTDIR@@errors are gone andconfigurereports that ZLIB was found but ICU was not. That’s understandable as I’ve not installed ICU manually with Homebrew (as you did in https://github.com/mongodb/mongo-php-driver/issues/883#issuecomment-406143360). The build ultimately succeeds and instructs me to add “extnesion=mongodb.so” tophp.ini.I add
extension=mongodb.soto/Applications/XAMPP/xamppfiles/etc/php.iniand confirm that the extension is loaded by the XAMPP’s CLI environment:I return Safari, which has been open to
http://mongodbs-mackbook-pro.local/dashboardsince XAMPP was installed. There is a “PHPInfo” link at the top, which simply displaysphpinfo()output on its own page. This reports that the PHP web SAPI is using the same INI file as the CLI environment; however, themongodbextension is not listed. That is to be expected, as the Apache process and its PHP module has not been restarted. I open the XAMPP control panel, restart the “Apache Web Server”, and then reload the “PHPInfo” dashboard page. Themongodbextension is still not listed.phpinfo()reports that the PHP error log is `/Applications/XAMPP/xamppfiles/logs/php_error_log, so I tail that and find:Searching Google for this error turned up a number of forum threads referring to
DYLD_LIBRARY_PATH. These two threads stood out:ffmpegfrom a PHP script usingexec(), which demonstrates that this environment variable does not just affect the loading of PHP extensions.DYLD_LIBRARY_PATHon macOS, and provides a lot of context about how it works. It also refers to aDYLD_FALLBACK_LIBRARY_PATHenvironment variable, but I did not see that utilized at all in XAMPP and did not pursue it.I’ll note that
DYLD_LIBRARY_PATHactually appears as an environment variable inphpinfo()output with the value/Applications/XAMPP/xamppfiles/lib/. XAMPP appears to setDYLD_LIBRARY_PATHin/Applications/XAMPP/xamppfiles/bin/envvars. This script checks if a path is already assigned and will prepend/Applications/XAMPP/xamppfiles/lib/if so, or simply assign/Applications/XAMPP/xamppfiles/bin/is the environment variable was empty. On my fresh install of macOS High Sierra,DYLD_LIBRARY_PATHwas not defined so XAMPP was assigning its own path. This interfers with PHP’s ability to dynamicallymongodb.soand/or the libraries it was built with. I did look definingDYLD_LIBRARY_PATHto/usr/local/lib:/usr/libfirst and allowing XAMPP to prepend its own directory, but that did not help. I expect that some of the libraries shipping with XAMPP are not ABI compatible with those that ship with macOS, which were used to buildmongodb.so.Ultimately, I modified
/Applications/XAMPP/xamppfiles/bin/envvarsand commented out theexport DYLD_LIBRARY_PATHline. After restarting Apache from the XAMPP control panel, I noticed thatmongodbwas now successfully loaded by the PHP web SAPI and theDYLD_LIBRARY_PATHenvironment variable was no longer present. I’m hestitant to suggest this as a final solution, as XAMPP’s Apache or PHP environments may still be relying onDYLD_LIBRARY_PATHto load other libraries. This may be especially true for the other PHP extensions that ship with XAMPP.In conclusion, there is definitely a conflict with XAMPP; however, I don’t believe this is limited to the MongoDB driver and suspect it extends to other PECL extensions that dynamically link shared libraries. I’d argue that the best solution is to install PHP using Homebrew and manually install extensions with its
peclcommand (extension formulae no longer exist since the PHP tap was deprecated). If using XAMPP is a priority, I think the XAMPP-VM environment is preferable to their standard macOS package, as it runs PHP inside of a Linux VM. Lastly, I’ll concede that the suggestion in https://github.com/mongodb/mongo-php-driver/issues/822#issuecomment-406271673 to use MAMP is also well founded.Sorry to bump an old thread. However, this came up in a Google search while trying to fix my issue. It is similar/related and this info may help someone else who stumbles here.
NOTE: I am on MacOS Catalina and using XAMPP. This issue was present for people on High Sierra and others as well.
I was getting:
Notice it’s complaining about
usprep.hand make fails. While searching, this was due toicu4c. I had it insalled via homebrew, it was a minor version out of date… updated it just because, no luck. hmm…After banging my head, I ended up doing
which icu4cwhich obviously failed (turns out isn’t a real binary lol). I then triedwhich icuinfo, and immediately saw (hoped) that I just figured out the issue. It was pulling from my XAMPP bin directory.I had to modify the paths to get the bin and sbin dirs for icu4c to be searched first.
More info on my SO answer here: https://stackoverflow.com/a/67349734/2703135
I hope it helps someone 😃
Ah i got it
it solved my problem, thank you for some clue.