Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP returns error 500 in browser, but not in shell

I'm currently experimenting with a PHP plugin called Mosquitto PHP (https://github.com/mgdm/Mosquitto-PHP/). I've got it all installed right, and under 'php -m' it seems to show up properly.

I'm using a small test code to see if it in it's basic form works:

<?php

$c = new Mosquitto\Client;
$c->onConnect(function() use ($c) {
    $c->publish('mgdm/test', 'Hello', 2);
});

$c->connect('test.mosquitto.org');

for ($i = 0; $i < 100; $i++) {
    // Loop around to permit the library to do its work
    $c->loop(1);
}

echo "Finished\n";
?>

And that seemed to return "Finished" in my browser. So, I decided to up my game, and add a TLS connection, as documented, to this:

<?php

$c = new Mosquitto\Client;
$c->onConnect(function() use ($c) {
    $c->publish('mgdm/test', 'Hello', 2);
});

$c->setTlsCertificates('mosquitto.org.crt');
$c->connect('test.mosquitto.org', '8883');

for ($i = 0; $i < 100; $i++) {
    $c->loop(1);
}

echo "Finished\n";
?>

I got the certificate and I've made sure apache2 could read it and set the ownership subsequently to apache2. This turned out to give me the 500 internal sever error in my browser.

-rwsrwsrwt  1 www-data     www-data        279 Jun  5 04:12 test.php
-rwxrwxrwx  1 www-data www-data   1078 Jun 30  2012 mosquitto.org.crt

Out of curiousity, I navigated to the script in shell and ran it with:

sudo php test.php

This resulting in a printed "Finished" in my ssh, and it sent the message through the broker.

This made me think it's an odd sort of permission error. Investigating further, I found these in my logs:

My apache2 log:

mod_fcgid: process /var/www/php-fcgi-scripts/web1/.php-fcgi-starter(20614) exit(communication error), get unexpected signal 11

mog_fcgid installed is:

libapache2-mod-fcgid 1:2.3.9-1+b1 amd64 FastCGI interface module for Apache 2

and it is, same with suexec is enabled as far as I can tell.:

Module fcgid already enabled
Module suexec already enabled

In a small twist of events, I changed the .php to .fcgi and gave it +x permission, and now the messages goes through the broker, but still it gives a 500 error in my browser.

suexec log shows:

[2016-06-07 14:05:58]: uid: (5004/web1) gid: (5005/client0) cmd: test.fcgi

and in my ispconfig log it shows:

[Tue Jun 07 14:08:25.567945 2016] [fcgid:warn] [pid 27861] (104)Connection reset by peer: [client 93.135.88.60:49328] mod_fcgid: error reading data from FastCGI server
[Tue Jun 07 14:08:25.568016 2016] [core:error] [pid 27861] [client 93.135.88.60:49328] End of script output before headers: test.fcgi

I'm totally lost for words here.. I need help!!

like image 666
user5740843 Avatar asked Oct 19 '22 08:10

user5740843


1 Answers

Try to increase the memory for php-fcgi (by default for cli memory_limit=-1).

I think this case should resolve your problem.

UPDATE

I have installed mosquitto (from php7 branch) and try it (run test.php from repository examples. php 7.0.7). And i have segfault to

segfault at 8 ip 00005574a41c753f sp 00007ffc2dc85da0 error 6 in php7.0[5574a3f80000+391000]

It seems that this is extension bug. You can try to debug this segfault (https://bugs.php.net/bugs-generating-backtrace.php) and send report to extension developers.

like image 180
Dmytro Avatar answered Oct 21 '22 01:10

Dmytro