Search code examples
phpmongodbmacosapache

MacOS apache doesn't load php 8.3.1 mongodb extension


I need help with including mongodb extension for php in apache on MacOs. I installed php8.3.1, apache Apache/2.4.56 (Unix) and included mongodb extension in php (extension="/usr/local/lib/php/pecl/20230831/mongodb.so"). Also included phpmodule in apache "LoadModule php_module /usr/local/Cellar/php/8.3.1/lib/httpd/modules/libphp.so".

And when I check php modules in terminal I see mongodb there:

olegk@olg buddy-web % php -v
PHP 8.3.1 (cli) (built: Dec 20 2023 12:44:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.1, Copyright (c), by Zend Technologies

olegk@olg buddy-web % php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/8.3
Loaded Configuration File:         /usr/local/etc/php/8.3/php.ini
Scan for additional .ini files in: /usr/local/etc/php/8.3/conf.d
Additional .ini files parsed:      /usr/local/etc/php/8.3/conf.d/ext-opcache.ini

olegk@olg buddy-web % php -m
[PHP Modules]
....
mongodb
....

But when I checked phpinfo() I don't see mongodb module there screenshot of phpinfo

I tried already all possible things and it still not load mogodb in apache. Maybe you know where issue can be?


Solution

  • If someone will have this problem. Here is link that helped me. Need to install httpd and it will not use extension validation.

    mongodb.so will work there.

    Quick steps:

    1. sudo apachectl stop <- stop default Apache2 from Apple
    2. sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist <- remove default Apache from launchd (autostart)
    3. brew install httpd <- install apache2 from homebrew
    4. sudo brew services start httpd

    Default port for Apache from brew is 8080 you should change it in the config files, also add at the end of the conf file Include /private/etc/apache2/other/*.conf the config is located in /usr/local/etc/httpd/httpd.conf