In working my way through installing the Debian package on Ubuntu 16.04, I ran into this:

502 Bad Gateway
nginx/1.10.0 (Ubuntu)

Looking at the error log:

2016/07/19 22:12:30 [error] 31806#31806: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 1.2.3.4, server: aegir.dev.example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "aegir.dev.example.com"

So I compared the Aegir configuration with what I have on Ubuntu 12.04, and found that the PHP FPM modes are different.

I tracked it down to these two stanzas in http/Provision/Service/http/nginx.php:

Line 73:

    // Check if there is php-fpm listening on unix socket, otherwise use port 9000 to connect
    if (provision_file()->exists('/var/run/php5-fpm.sock')->status()) {
      $this->server->phpfpm_mode = 'socket';
      drush_log(dt('PHP-FPM unix socket mode detected -SAVE- YES socket found @path.', array('@path' => '/var/run/php5-fpm.sock')));
    }
    else {
      $this->server->phpfpm_mode = 'port';
      drush_log(dt('PHP-FPM port mode detected -SAVE- NO socket found @path.', array('@path' => '/var/run/php5-fpm.sock')));
    }

Line 135:

    // Check if there is php-fpm listening on unix socket, otherwise use port 9000 to connect
    if (provision_file()->exists('/var/run/php5-fpm.sock')->status()) {
      $this->server->phpfpm_mode = 'socket';
      drush_log(dt('PHP-FPM unix socket mode detected -VERIFY- YES socket found @path.', array('@path' => '/var/run/php5-fpm.sock')));
    }
    else {
      $this->server->phpfpm_mode = 'port';
      drush_log(dt('PHP-FPM port mode detected -VERIFY- NO socket found @path.', array('@path' => '/var/run/php5-fpm.sock')));
    }

So it's obvious that the code is only looking for the PHP 5 socket file, not the new PHP 7 one located at /var/run/php/php7.0-fpm.sock. We need to check for this one as well.

In addition, given that the filenames are in there as string literals mutliple times, we should set these up as variables so that they're only set once. Then we can use those variables everywhere they're needed. So we can do something like this:

$socket_path_php5 = '/var/run/php5-fpm.sock';
$socket_path_php7 = '/var/run/php/php7.0-fpm.sock;
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

colan created an issue. See original summary.

colan’s picture

Assigned: Unassigned » colan
colan’s picture

Status: Active » Needs work
FileSize
4.13 KB

Here's a preliminary attempt. I'll get the missing elements included as well, but please review this patch anyway.

Remaining tasks:

  • HTTPS in http/Provision/Service/http/nginx/ssl.php
  • Template file http/Provision/Config/Nginx/subdir.tpl.php
  • Template file http/Provision/Config/Nginx/Inc/vhost_include.tpl.php

The HTTPS support will need to be ported to Aegir HTTPS in Stop assuming PHP is always at version 5 once we finish here.

memtkmcc’s picture

Looks good to me, if the standard path to PHP 7 socket is /var/run/php/php7.0-fpm.sock ( I don't know, because in BOA we are using custom paths per Octopus instance and per PHP version). We need this fix in those other files, too.

memtkmcc’s picture

Hmm.. I can't test this with BOA, because it is never used in BOA, look:

<?php if ($satellite_mode == 'boa'): ?>
    fastcgi_pass  unix:/var/run/$user_socket.fpm.socket;
<?php elseif ($phpfpm_mode == 'port'): ?>
    fastcgi_pass  127.0.0.1:9000;
<?php else: ?>
    fastcgi_pass  unix:/var/run/php5-fpm.sock;
<?php endif; ?>

That said, you can always apply a patch on some test vanilla Aegir instance and re-verify it to see if it works as expected, it works on server verify, not only on install:

1. Apply the patch
2. su -s /bin/bash aegir -c "drush @hm hosting-task @server_master verify --force"

Of course it will NOT work, because currently that line is hardcoded:

fastcgi_pass unix:/var/run/php5-fpm.sock;

Well, this means that your patch is not enough and should be rewritten needs to provide more specific values for $phpfpm_mode, so in the template we could use something like:

<?php if ($satellite_mode == 'boa'): ?>
    fastcgi_pass  unix:/var/run/$user_socket.fpm.socket;
<?php elseif ($phpfpm_mode == 'port'): ?>
    fastcgi_pass  127.0.0.1:9000;
<?php elseif ($phpfpm_mode == 'socket5'): ?>
    fastcgi_pass  unix:/var/run/php5-fpm.sock;
<?php elseif ($phpfpm_mode == 'socket7'): ?>
    fastcgi_pass  unix:/var/run/php/php7.0-fpm.sock;
<?php endif; ?>
memtkmcc’s picture

The fix will be trivial:

+    // Search for socket files or fall back to port mode.
+    switch (TRUE) {
+      case provision_file()->exists(self::SOCKET_PATH_PHP5)->status():
+        $mode = 'socket5';
+        $socket_path = self::SOCKET_PATH_PHP5;
+      break;
+      case provision_file()->exists(self::SOCKET_PATH_PHP7)->status():
+        $mode = 'socket7';
+        $socket_path = self::SOCKET_PATH_PHP7;
+      break;
+      default:
+        $mode = 'port';
+        $socket_path = '';
+      break;
+    }

memtkmcc’s picture

At least, it will be simpler that adding $socket_path as available variable in the template, so we don't hardcode it there via extra if/else. But, you decide.

memtkmcc’s picture

It could be also:

<?php if ($satellite_mode == 'boa'): ?>
    fastcgi_pass  unix:/var/run/$user_socket.fpm.socket;
<?php elseif ($phpfpm_mode == 'socket5'): ?>
    fastcgi_pass  unix:/var/run/php5-fpm.sock;
<?php elseif ($phpfpm_mode == 'socket7'): ?>
    fastcgi_pass  unix:/var/run/php/php7.0-fpm.sock;
<?php else: ?>
    fastcgi_pass  127.0.0.1:9000;
<?php endif; ?>
colan’s picture

Status: Needs work » Needs review
FileSize
12.22 KB

All done. Needs testing.

colan’s picture

Status: Needs review » Fixed
FileSize
12.21 KB
684 bytes

I had to change one thing before I could get it to work. I was using drupal_strtoupper(), but this wasn't being included as we're running under Drush. I made some attempts to include the command file, but wasn't successful. We're dealing with ASCII here so it's no major loss. I simply switched to PHP's strtoupper(), and all was well.

  • colan committed 89b462e on 7.x-3.x
    Issue #2769587 by colan: Check for PHP 7 FPM sockets as well as in PHP 5...
memtkmcc’s picture

Perfect!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.