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 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
    • ¥15 活动选择题。最多可以参加几个项目?
    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题
    • ¥20 云服务Linux系统TCP-MSS值修改?
    • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
    • ¥20 怎么在stm32门禁成品上增加查询记录功能
    • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
    • ¥50 NT4.0系统 STOP:0X0000007B
    • ¥15 想问一下stata17中这段代码哪里有问题呀