From a0d66f292b8c2a9e87a7d70c97b47561545e343f Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sun, 24 Nov 2024 08:25:22 +0700 Subject: [PATCH] Allow turn php off --- src/executor/nginx.js | 6 +++--- src/executor/runnersub.js | 28 ++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/executor/nginx.js b/src/executor/nginx.js index c89299f..17b052a 100644 --- a/src/executor/nginx.js +++ b/src/executor/nginx.js @@ -24,7 +24,7 @@ const passengerKeys = [ const locationKeys = [ "root", "alias", "rewrite", "try_files", "return", "index", "expires", "allow", "deny", "autoindex", "proxy_pass", - "limit_except", "limit_rate", "limit_rate_after" + "limit_except", "limit_rate", "limit_rate_after", "default_type" ]; const sslNames = ["", "off", "always", "on"]; const wwwNames = ["", "off", "always", "on"]; @@ -209,8 +209,8 @@ class NginxExecutor { if (node.location) { r.locations = []; for (const l of (node.location)) { - if (l.fastcgi_pass) { - if (l.return) { + if (l.fastcgi_pass || /^~ "?\.php/.test(l._value)) { + if (l.return || !l.fastcgi_pass) { r.fastcgi = "off"; } else if (l.try_files) { r.fastcgi = "on"; diff --git a/src/executor/runnersub.js b/src/executor/runnersub.js index 1fa2be7..140d188 100644 --- a/src/executor/runnersub.js +++ b/src/executor/runnersub.js @@ -194,21 +194,45 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec, case 'php': if (value == 'lts' || value == 'latest') { value = getLtsPhp(); + } else if (value == 'off') { + value = 'off'; } else if (!value.includes('.')) { value = getLtsPhp(value); } + if (!value) { throw new Error(`php version ${value} not found`); } + if (value == 'off') { + await writeLog("$> Turning off PHP engine"); + await virtExec("modify-web", { + domain: subdomain, + mode: 'none', + }); + await sshExec(`rm -f ~/.local/bin/php`, false); + await writeLog("$> Updating nginx config"); + const nginxNodes = await nginxExec.get(subdomain); + nginxInfos = nginxExec.extractInfo(nginxNodes, subdomain); + await writeLog(await nginxExec.setDirect(subdomain, nginxInfos)); + break; + } + await writeLog("$> Changing PHP engine to " + value); - if (process.env.MODE !== 'dev') { + + if (subdomain['PHP execution mode'] == 'none') { await virtExec("modify-web", { domain: subdomain, - 'php-version': value, + mode: 'fpm', + 'php-fpm-mode': 'ondemand', }); } + await virtExec("modify-web", { + domain: subdomain, + 'php-version': value, + }); + var phpVer = value.replace('.', ''); await sshExec(`mkdir -p ~/.local/bin; echo -e "\\u23\\u21/bin/bash\\n$(which php${phpVer}) \\u22\\u24\\u40\\u22" > ~/.local/bin/php; chmod +x ~/.local/bin/php`, false); break;