Skip to content

Commit

Permalink
Allow turn php off
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Nov 24, 2024
1 parent 9198e9b commit a0d66f2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/executor/nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -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";
Expand Down
28 changes: 26 additions & 2 deletions src/executor/runnersub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a0d66f2

Please sign in to comment.