From 7de7a00fb83f89645af23f976f247d8740000664 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 00:42:07 +0000 Subject: [PATCH 1/5] Initial plan From 2cce81d6e7110e73151ed2f1a504afe4497284c8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 00:45:46 +0000 Subject: [PATCH 2/5] Add sitehost:prepare:serverconfig command for per-host PHP config Co-authored-by: brad-ps <107819630+brad-ps@users.noreply.github.com> --- README.md | 26 ++++++++++++++++++++++++-- ps_silverstripe.php | 22 +++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1df963d..4e76fcb 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ `dep sitehost:prepare` +`dep sitehost:prepare:serverconfig` + `dep sitehost:prepare:deploy stage=uat --branch=master` `dep sitehost:backup` @@ -115,7 +117,10 @@ host('uat.domain.co.nz') ->set('remote_user', 'uatuser') ->set('sitehost_server_name', 'ch-xxx') ->set('sitehost_stack_name', 'xxxxxxxxx') - ->set('sitehost_restart_mode', 'apache-php'); //Optional + ->set('sitehost_restart_mode', 'apache-php') //Optional + ->set('php_memory_limit', '512M') //Optional - default 512M + ->set('php_post_max_size', '64M') //Optional - default 64M + ->set('php_max_execution_time', '60'); //Optional - default 60 //Production @@ -139,7 +144,7 @@ This will: - Delete public directory which is created on first creation of a Sitehost server, so we can use this path as a symlink - Generates ssh key which you can copy to deployment keys on github project -- Create php default config +- Create/update php server config (memory_limit, post_max_size, max_execution_time) If you are doing a container upgrade on Sitehost then you will want to run this command immediately after @@ -199,6 +204,23 @@ This is only available on certain containers. `->set('sitehost_restart_mode', 'apache-php');` +### PHP server config + +Each deployment runs `sitehost:prepare:serverconfig` which writes PHP settings to `~/container/config/php/conf.d/ps-custom.ini`. + +The following settings can be configured globally or per host in your `deploy.php`: + +```php +->set('php_memory_limit', '512M') // default: 512M +->set('php_post_max_size', '64M') // default: 64M +->set('php_max_execution_time', '60') // default: 60 +``` + +You can also run this command manually to update PHP config without a full deployment: + +`dep sitehost:prepare:serverconfig` + + ### Docker Deployer comes with ps docker image. diff --git a/ps_silverstripe.php b/ps_silverstripe.php index 156dee5..9114ea6 100644 --- a/ps_silverstripe.php +++ b/ps_silverstripe.php @@ -17,6 +17,11 @@ set('shared_path', '/container/application/shared'); set('sitehost_restart_mode', 'container'); //This can also be set to apache +// PHP server config defaults - override per host in deploy.php +set('php_memory_limit', '512M'); +set('php_post_max_size', '64M'); +set('php_max_execution_time', '60'); + /** * Sitehost - this is the upgrade script from mysql 5.7 to 8 * This will immediately make the changes to the environment @@ -67,7 +72,7 @@ task('sitehost:prepare', [ 'sitehost:symlink', 'sitehost:ssh', - 'sitehost:phpconfig', + 'sitehost:prepare:serverconfig', 'sitehost:listreleases' ]); @@ -129,6 +134,20 @@ } }); +/** + * Sitehost - Write PHP server config settings to ps-custom.ini. + * Values can be overridden per host in deploy.php: + * ->set('php_memory_limit', '256M') + * ->set('php_post_max_size', '32M') + * ->set('php_max_execution_time', '30') + */ +task('sitehost:prepare:serverconfig', function () { + writeln('Writing PHP server config to "~/container/config/php/conf.d/ps-custom.ini"'); + run('echo "memory_limit={{php_memory_limit}}" > ~/container/config/php/conf.d/ps-custom.ini'); + run('echo "post_max_size={{php_post_max_size}}" >> ~/container/config/php/conf.d/ps-custom.ini'); + run('echo "max_execution_time={{php_max_execution_time}}" >> ~/container/config/php/conf.d/ps-custom.ini'); +}); + /** * Sitehost */ @@ -491,6 +510,7 @@ // TODO: check if required 'deploy:clear_paths', 'silverstripe:buildflush', 'deploy:publish', + 'sitehost:prepare:serverconfig', 'sitehost:restart' ]); From 46088b32160e29729d1c8043529bf68f2dee9a35 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 00:49:27 +0000 Subject: [PATCH 3/5] Rename sitehost:prepare:serverconfig to sitehost:phpconfig Co-authored-by: brad-ps <107819630+brad-ps@users.noreply.github.com> --- README.md | 8 +++----- ps_silverstripe.php | 23 +++-------------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 4e76fcb..1875d43 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,7 @@ `dep sitehost:prepare` -`dep sitehost:prepare:serverconfig` - -`dep sitehost:prepare:deploy stage=uat --branch=master` +`dep sitehost:phpconfig` `dep sitehost:backup` @@ -206,7 +204,7 @@ This is only available on certain containers. ### PHP server config -Each deployment runs `sitehost:prepare:serverconfig` which writes PHP settings to `~/container/config/php/conf.d/ps-custom.ini`. +Each deployment runs `sitehost:phpconfig` which writes PHP settings to `~/container/config/php/conf.d/ps-custom.ini`. The following settings can be configured globally or per host in your `deploy.php`: @@ -218,7 +216,7 @@ The following settings can be configured globally or per host in your `deploy.ph You can also run this command manually to update PHP config without a full deployment: -`dep sitehost:prepare:serverconfig` +`dep sitehost:phpconfig` ### Docker diff --git a/ps_silverstripe.php b/ps_silverstripe.php index 9114ea6..79995bd 100644 --- a/ps_silverstripe.php +++ b/ps_silverstripe.php @@ -72,7 +72,7 @@ task('sitehost:prepare', [ 'sitehost:symlink', 'sitehost:ssh', - 'sitehost:prepare:serverconfig', + 'sitehost:phpconfig', 'sitehost:listreleases' ]); @@ -117,23 +117,6 @@ } }); -/** - * Sitehost - */ -task('sitehost:phpconfig', function () { - //Update php config to default - if (test('[ ! -f ~/container/config/php/conf.d/ps-custom.ini ]')) { - writeln('No default custom php has been configured'); - writeln('Creating "~/container/config/php/conf.d/ps-custom.ini" and adding defaults'); - run('echo "memory_limit=512M" >> ~/container/config/php/conf.d/ps-custom.ini'); - //TODO: POST_MAX - //TODO: EXECUTION TIME - //TODO: UPLOAD_MAX - } else { - writeln('php has been configured - skipping'); - } -}); - /** * Sitehost - Write PHP server config settings to ps-custom.ini. * Values can be overridden per host in deploy.php: @@ -141,7 +124,7 @@ * ->set('php_post_max_size', '32M') * ->set('php_max_execution_time', '30') */ -task('sitehost:prepare:serverconfig', function () { +task('sitehost:phpconfig', function () { writeln('Writing PHP server config to "~/container/config/php/conf.d/ps-custom.ini"'); run('echo "memory_limit={{php_memory_limit}}" > ~/container/config/php/conf.d/ps-custom.ini'); run('echo "post_max_size={{php_post_max_size}}" >> ~/container/config/php/conf.d/ps-custom.ini'); @@ -510,7 +493,7 @@ // TODO: check if required 'deploy:clear_paths', 'silverstripe:buildflush', 'deploy:publish', - 'sitehost:prepare:serverconfig', + 'sitehost:phpconfig', 'sitehost:restart' ]); From bcf313257325772ccdeee37af2032ff54a42cb06 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 01:19:24 +0000 Subject: [PATCH 4/5] Plan: create dir+file if missing, fix shell escaping Co-authored-by: brad-ps <107819630+brad-ps@users.noreply.github.com> --- README.md | 2 +- ps_silverstripe.php | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1875d43..1668006 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ This is only available on certain containers. ### PHP server config -Each deployment runs `sitehost:phpconfig` which writes PHP settings to `~/container/config/php/conf.d/ps-custom.ini`. +Each deployment runs `sitehost:phpconfig` which updates the managed PHP settings in `~/container/config/php/conf.d/ps-custom.ini`, patching only the relevant lines so any other config in the file is preserved. The following settings can be configured globally or per host in your `deploy.php`: diff --git a/ps_silverstripe.php b/ps_silverstripe.php index 79995bd..6255511 100644 --- a/ps_silverstripe.php +++ b/ps_silverstripe.php @@ -125,10 +125,20 @@ * ->set('php_max_execution_time', '30') */ task('sitehost:phpconfig', function () { - writeln('Writing PHP server config to "~/container/config/php/conf.d/ps-custom.ini"'); - run('echo "memory_limit={{php_memory_limit}}" > ~/container/config/php/conf.d/ps-custom.ini'); - run('echo "post_max_size={{php_post_max_size}}" >> ~/container/config/php/conf.d/ps-custom.ini'); - run('echo "max_execution_time={{php_max_execution_time}}" >> ~/container/config/php/conf.d/ps-custom.ini'); + $ini = '~/container/config/php/conf.d/ps-custom.ini'; + writeln('Updating PHP server config in "' . $ini . '"'); + run('touch ' . $ini); + $settings = [ + 'memory_limit' => get('php_memory_limit'), + 'post_max_size' => get('php_post_max_size'), + 'max_execution_time' => get('php_max_execution_time'), + ]; + foreach ($settings as $key => $value) { + // Replace the existing line if present, otherwise append + run('grep -q "^' . $key . '=" ' . $ini + . ' && sed -i "s|^' . $key . '=.*|' . $key . '=' . $value . '|" ' . $ini + . ' || echo "' . $key . '=' . $value . '" >> ' . $ini); + } }); /** From 3fa24d174d2df2687ce479fae33f83e2ffc927ef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 01:20:39 +0000 Subject: [PATCH 5/5] Ensure dir+file created if missing; fix shell escaping in phpconfig task Co-authored-by: brad-ps <107819630+brad-ps@users.noreply.github.com> --- ps_silverstripe.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ps_silverstripe.php b/ps_silverstripe.php index 6255511..d2d1929 100644 --- a/ps_silverstripe.php +++ b/ps_silverstripe.php @@ -127,17 +127,24 @@ task('sitehost:phpconfig', function () { $ini = '~/container/config/php/conf.d/ps-custom.ini'; writeln('Updating PHP server config in "' . $ini . '"'); - run('touch ' . $ini); + // Ensure the directory and file exist before patching + run('mkdir -p ~/container/config/php/conf.d && touch ' . $ini); $settings = [ - 'memory_limit' => get('php_memory_limit'), - 'post_max_size' => get('php_post_max_size'), + 'memory_limit' => get('php_memory_limit'), + 'post_max_size' => get('php_post_max_size'), 'max_execution_time' => get('php_max_execution_time'), ]; foreach ($settings as $key => $value) { + // Escape value for sed replacement (|, \, and & are special in the replacement string). + // strtr() is used instead of str_replace() to avoid double-escaping when the value + // contains multiple metacharacters (str_replace processes needles sequentially). + $sedValue = strtr($value, ['\\' => '\\\\', '|' => '\\|', '&' => '\\&']); + // Escape value for shell echo (handles spaces, quotes, etc.) + $shellValue = escapeshellarg($value); // Replace the existing line if present, otherwise append - run('grep -q "^' . $key . '=" ' . $ini - . ' && sed -i "s|^' . $key . '=.*|' . $key . '=' . $value . '|" ' . $ini - . ' || echo "' . $key . '=' . $value . '" >> ' . $ini); + run("grep -q '^{$key}=' {$ini}" + . " && sed -i 's|^{$key}=.*|{$key}={$sedValue}|' {$ini}" + . " || echo {$key}={$shellValue} >> {$ini}"); } });