Commit 89b462ec authored by colan's avatar colan

Issue #2769587 by colan: Check for PHP 7 FPM sockets as well as in PHP 5.

parent 5133c92d
......@@ -19,6 +19,10 @@ if (!$phpfpm_mode && $server->phpfpm_mode) {
$phpfpm_mode = $server->phpfpm_mode;
}
// We can use $server here once we have proper inheritance.
// See Provision_Service_http_nginx_ssl for details.
$phpfpm_socket_path = Provision_Service_http_nginx::getPhpFpmSocketPath();
$nginx_is_modern = drush_get_option('nginx_is_modern');
if (!$nginx_is_modern && $server->nginx_is_modern) {
$nginx_is_modern = $server->nginx_is_modern;
......@@ -227,7 +231,7 @@ location = /fpm-status {
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
}
......@@ -243,7 +247,7 @@ location = /fpm-ping {
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
}
<?php endif; ?>
......@@ -266,7 +270,7 @@ location = /cron.php {
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
}
......@@ -915,7 +919,7 @@ location ~* /(?:modules|libraries)/(?:contrib/)?(?:ad|tinybrowser|f?ckeditor|tin
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
}
......@@ -1066,7 +1070,7 @@ location ~ ^/(?<esi>esi/.*)"$ {
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
###
### Use Nginx cache for all visitors.
......@@ -1220,7 +1224,7 @@ location = /index.php {
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
<?php if ($nginx_has_upload_progress): ?>
track_uploads uploads 60s; ### required for upload progress
......@@ -1274,7 +1278,7 @@ location ~* ^/(?:index|cron|boost_stats|update|authorize|xmlrpc)\.php$ {
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
}
......@@ -1304,7 +1308,7 @@ location @allowupdate {
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
}
<?php endif; ?>
......
......@@ -19,6 +19,10 @@ if (!$phpfpm_mode && $server->phpfpm_mode) {
$phpfpm_mode = $server->phpfpm_mode;
}
// We can use $server here once we have proper inheritance.
// See Provision_Service_http_nginx_ssl for details.
$phpfpm_socket_path = Provision_Service_http_nginx::getPhpFpmSocketPath();
$nginx_is_modern = drush_get_option('nginx_is_modern');
if (!$nginx_is_modern && $server->nginx_is_modern) {
$nginx_is_modern = $server->nginx_is_modern;
......@@ -315,7 +319,7 @@ location ^~ /<?php print $subdir; ?> {
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
}
......@@ -781,7 +785,7 @@ location ^~ /<?php print $subdir; ?> {
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
}
......@@ -980,7 +984,7 @@ location ^~ /<?php print $subdir; ?> {
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
}
......@@ -1059,7 +1063,7 @@ location ^~ /<?php print $subdir; ?> {
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
<?php if ($nginx_has_upload_progress): ?>
track_uploads uploads 60s; ### required for upload progress
......@@ -1207,7 +1211,7 @@ location @allowupdate_<?php print $subdir_loc; ?> {
<?php elseif ($phpfpm_mode == 'port'): ?>
fastcgi_pass 127.0.0.1:9000;
<?php else: ?>
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:<?php print $phpfpm_socket_path; ?>;
<?php endif; ?>
}
<?php endif; ?>
......
<?php
class Provision_Service_http_nginx extends Provision_Service_http_public {
// Define socket file locations for various PHP versions.
const SOCKET_PATH_PHP5 = '/var/run/php5-fpm.sock';
const SOCKET_PATH_PHP7 = '/var/run/php/php7.0-fpm.sock';
protected $application_name = 'nginx';
protected $has_restart_cmd = TRUE;
......@@ -71,14 +76,7 @@ class Provision_Service_http_nginx extends Provision_Service_http_public {
}
// 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')));
}
$this->server->phpfpm_mode = $this->getPhpFpmMode('save');
// Check if there is BOA specific global.inc file to enable extra Nginx locations
if (provision_file()->exists('/data/conf/global.inc')->status()) {
......@@ -133,14 +131,7 @@ class Provision_Service_http_nginx extends Provision_Service_http_public {
}
// 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')));
}
$this->server->phpfpm_mode = $this->getPhpFpmMode('verify');
// Check if there is BOA specific global.inc file to enable extra Nginx locations
if (provision_file()->exists('/data/conf/global.inc')->status()) {
......@@ -161,6 +152,70 @@ class Provision_Service_http_nginx extends Provision_Service_http_public {
parent::verify_server_cmd();
}
/**
* Determines the PHP FPM mode.
*
* @param string $server_task
* The server task type for logging purposes. Leave blank to skip logging.
* @return string
* The mode, either 'socket' or 'port'.
*/
public static function getPhpFpmMode($server_task = NULL) {
// Search for socket files or fall back to port mode.
switch (TRUE) {
case provision_file()->exists(self::SOCKET_PATH_PHP5)->status():
$mode = 'socket';
$socket_path = self::SOCKET_PATH_PHP5;
break;
case provision_file()->exists(self::SOCKET_PATH_PHP7)->status():
$mode = 'socket';
$socket_path = self::SOCKET_PATH_PHP7;
break;
default:
$mode = 'port';
$socket_path = '';
break;
}
// Report results in the log if requested.
if (!empty($server_task)) {
drush_log(dt('PHP-FPM @mode mode detected -' . '@task' . '- @yes_or_no socket found @path.', array(
'@mode' => ($mode == 'socket') ? 'unix socket' : 'port',
'@task' => strtoupper($server_task),
'@yes_or_no' => ($mode == 'socket') ? 'YES' : 'NO',
'@path' => ($socket_path ? $socket_path : self::SOCKET_PATH_PHP5 . ' or ' . self::SOCKET_PATH_PHP7),
)));
}
// Return the discovered mode.
return $mode;
}
/**
* Gets the PHP FPM unix socket path.
*
* If we're running in port mode, there is no socket path. FALSE would be
* returned in this case.
*
* @return string
* The path, or FALSE if there isn't one.
*/
public static function getPhpFpmSocketPath() {
// Simply return FALSE if we're in port mode.
if (self::getPhpFpmMode() == 'port') {
return FALSE;
}
// Return the socket path based on the PHP version.
if (strtok(phpversion(), '.') == 7) {
return self::SOCKET_PATH_PHP7;
}
else {
return self::SOCKET_PATH_PHP5;
}
}
/**
* Guess at the likely value of the http_restart_cmd.
*
......
......@@ -80,14 +80,7 @@ class Provision_Service_http_nginx_ssl extends Provision_Service_http_ssl {
}
// 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')));
}
$this->server->phpfpm_mode = Provision_Service_http_nginx::getPhpFpmMode('save');
// Check if there is BOA specific global.inc file to enable extra Nginx locations
if (provision_file()->exists('/data/conf/global.inc')->status()) {
......@@ -133,14 +126,7 @@ class Provision_Service_http_nginx_ssl extends Provision_Service_http_ssl {
}
// 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')));
}
$this->server->phpfpm_mode = Provision_Service_http_nginx::getPhpFpmMode('verify');
// Check if there is BOA specific global.inc file to enable extra Nginx locations
if (provision_file()->exists('/data/conf/global.inc')->status()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment