dougang8233 2017-04-23 18:16
浏览 55

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

UPDATE

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.

Config:

  • 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

<?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:

<?php
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://127.0.0.1:9007/Users/myuser/Projects/test/$1

Or

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

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.

<?php
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");
print_r($res);

It works like a charm.

Any help would be appreciated.

EDIT: composer.json contents as requested by a comment

{
    "require": {
        "mongodb/mongodb": "^1.1"
    }
}
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突