OSX(El Capitan) - 自制语言Apache 2.4 + PHP-FPM + mongoDB - 服务不可用


I've tried using PhpMyAdmin with the same configuration and I've got the same error 503 Service Unavailable. So it seems that it has nothing to do with the mongodb module but it's an Apache or PHP-FPM misconfiguration. In my opinion it's most probably the fcgi proxy which doesn't call php-fpm the proper way but I don't know what goes wrong.

Original question

I've been tearing my hair out for hours trying to find the a solution.


  • OSX (El Capitan)
  • homebrew Apache 2.4
  • php-fpm (5.5 or 7.0, I've tried both, same error!)

This works in index.php

echo phpinfo();

Php info

PHP Version 7.0.18
MongoDB extension version 1.2.8

I've tried calling a php in a subdirectory (I suspected that there is a problem with the proxy parameter) but it's working.

Conslusion so far:

  • apache is working
  • document root OK
  • default index OK (I've tried explicitly index.php anyway)
  • php-fpm is running
  • apache proxy to php-fpm working (see UPDATE above!)

Now the weird part

I change the contents of index.php to this:

require 'vendor/autoload.php';
$client = new MongoDB\Client("mongodb://localhost:3001");

The only composer module installed is mongodb/mongodb with composer require mongodb/mongodb

The result is simple 503 Service Unavailable

The parameter (mongodb://localhost:3001) in irrelevant I have the same error without any parameters or with intentionally bad parameters. (But in case you're wondering I'm trying to connect to the mongodb of a local development instance of a Meter application that's the reason for port 3001. And the connection is working from external program /Robomongo/)

Currently I'm using Apache ProxyPassMatch but I've tried SetHandler method as well (see below). I've tried with php-fpm 5.5 and php-fpm 7.0 (both installed with homebrew)

Apache config:

ProxyPassMatch ^/(.*\.php)$ fcgi://$1


<FilesMatch \.php$>
  SetHandler "proxy:fcgi://"

No error messages in Apache or php-fpm logs (even with loglevel debug) despite error logging is working (I've tried making a deliberate PHP syntax error and it generated the proper error message in php-fpm error log file) e.g.

require 'vendor/autoload.php'; // include Composer's autoloader
$client = new MongoDB;

The error message is clearly shown so the error logging is fine

Fatal error: Uncaught Error: Class 'MongoDB' not found in /Users/myuser/Projects/test/index.php:17 Stack trace: #0 {main} thrown in /Users/myuser/Projects/test/index.php on line 17

I've tried connecting to a MySQL database with this code:

$mysqli = new mysqli("localhost", "user", "password", "dbname");
$res = $mysqli->query("SELECT * FROM table");

It works like a charm.

Any help would be appreciated.

EDIT: composer.json contents as requested by a comment

    "require": {
        "mongodb/mongodb": "^1.1"
dongmo1708 你有没有得到这个?我在使用Magento2的mysql数据库上遇到了类似的问题。我相信这是一个Apache和php-fpm问题。也使用自制软件。我的proxypass匹配与您的相同。
接近 3 年之前 回复
douzhi1937 为什么不用MAMP运行PHP
3 年多之前 回复
dongwei7245 谢谢你的建议。我已经将问题缩小到Apache和php-fpm配置,请参阅更新部分
3 年多之前 回复
doudi5892 如果这个问题没有引起足够的重视
3 年多之前 回复
dongliuliu0385 也许试着在他们的github页面上打开一个问题?
3 年多之前 回复
duanganleng0577 当然,我已经添加了这个问题。正如您所看到的,这是一个完全空的测试项目。没有别的东西只是我所说的。3行PHP和一个作曲家模块。
3 年多之前 回复
doumi1912 你可以发布你的composer.json文件
3 年多之前 回复
douyinghuo8874 是的,正如我所提到的那样:“连接正在从外部程序/Robomongo/开始工作”
3 年多之前 回复
dongyinzheng6572 你能直接连接到Mongo吗?它甚至在运行吗?
3 年多之前 回复
Csdn user default icon