Skip to content

Allow PHP version to be changed from Site Settings - #225

Merged
wojtekn merged 9 commits into
trunkfrom
improve/php-version-picker
Jun 17, 2024
Merged

Allow PHP version to be changed from Site Settings#225
wojtekn merged 9 commits into
trunkfrom
improve/php-version-picker

Conversation

@danielbachhuber

@danielbachhuber danielbachhuber commented Jun 9, 2024

Copy link
Copy Markdown
Contributor

Related #32

Proposed Changes

Allows the PHP version to be changed from Site Settings:

CleanShot.2024-06-10.at.07.34.42.mp4

Also restarts the server after the PHP version is changed.

Testing Instructions

  1. Create a new site.
  2. New site should launch with a default version of PHP 8.0.
  3. Navigate to the Studio settings for the site.
  4. Edit the PHP version to a different PHP version.
  5. Verify the server restarts and the site is running the new PHP version.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@danielbachhuber danielbachhuber self-assigned this Jun 9, 2024
@danielbachhuber

danielbachhuber commented Jun 9, 2024

Copy link
Copy Markdown
Contributor Author

Not correctly saving/applying the PHP version quite yet. My intent is to have the PHP version saved in appdata-v1.json first, and then the server restarted from that data. I don't feel like I fully grok the data flow though.

Also need to handle invalid or outdated PHP version stored in appdata-v1.json (e.g. what should happen if "5.6" is present?)

Happy to take suggestions on the tests to add.

@derekblank

Copy link
Copy Markdown
Contributor

Not correctly saving/applying the PHP version quite yet. My intent is to have the PHP version saved in appdata-v1.json first, and then the server restarted from that data.

The PHP version is being saved correctly to appdata-v1.json, but it looks like the change wasn't being applied to update the site details in the UI (and when starting the server). #226 should fix this issue.

Also need to handle invalid or outdated PHP version stored in appdata-v1.json (e.g. what should happen if "5.6" is present?)

Potentially, we could just fallback to using DEFAULT_PHP_VERSION if the phpVersion value in appdata-v1.json is not one of the values listed in const availablePhpVersions = [ '7.4', '8.0', '8.1', '8.2' ];. Perhaps this array should be stored in constants, too.

* Add phpVersion to updateSiteDetails

* Update tests for changing the PHP version
@wojtekn
wojtekn requested a review from a team June 10, 2024 11:06
@matt-west

Copy link
Copy Markdown
Contributor

Thanks @danielbachhuber!

We had originally planned to add the PHP version picker to the add/edit site form under a new "Advanced settings" section. (Moving the local path field there too.) Clicking the edit link on the site settings screen would launch the full edit site modal.

Was that plan changed? (I may have missed any discussion there.)

I prefer the dedicated modal when editing the PHP version for an existing site. Assuming we're okay with maintaining the additional UI in the app. I think users should be able to set the PHP version when creating a new site too though.

image

@danielbachhuber

Copy link
Copy Markdown
Contributor Author

@matt-west I decided to add this implementation for now because I saw there was a lot of demand for a PHP version switcher and didn't want to go down the rabbit hole adding an overly complex form.

@katinthehatsite

Copy link
Copy Markdown
Contributor

I decided to add this implementation for now because I saw there was a lot of demand for a PHP version switcher

I have not looked at the PR yet but I think it would be good to have PHP version shipped before / around WC EU so that the app could be showcased with this feature. It has been requested and mentioned in multiple demo calls, P2s and conversations and was generally marked as one of the main blockers for not using Studio compared to Local.

@matt-west

Copy link
Copy Markdown
Contributor

@danielbachhuber Sounds good. We can add the Advanced settings dropdown to the new site form later.

@fluiddot fluiddot mentioned this pull request Jun 11, 2024
1 task

@fluiddot fluiddot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the PR and works as expected 🎊 . The only limitation I found is that demo sites don't use the PHP version set. As far as I've tested, they are always created with version 8.1.29. I wouldn't consider it a blocker but I presume users will expect that the PHP version matches between the local and demo site.

Comment thread src/site-server.ts Outdated
...this.details,
url: this.server.url,
port: this.server.options.port,
phpVersion: this.server.options.phpVersion || DEFAULT_PHP_VERSION,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: The phpVersion can be a supported value or undefined.

Suggested change
phpVersion: this.server.options.phpVersion || DEFAULT_PHP_VERSION,
phpVersion: this.server.options.phpVersion ?? DEFAULT_PHP_VERSION,
Comment thread src/constants.ts Outdated
* Use `DEFAULT_PHP_VERSION` constant from `wp-now`

* Use available PHP versions of Playground

* Add `web-streams-polyfill` package for unit tests

* Polyfill `ReadableStream` in unit tests

Web streams are used by `php-wasm`, so we need to polyfull them if we import the library in unit tests.
@danielbachhuber
danielbachhuber marked this pull request as ready for review June 11, 2024 18:38
@danielbachhuber

Copy link
Copy Markdown
Contributor Author

@Automattic/yolo I think this is ready for a review.

* Mock `matchMedia`

* Expose label in `SettingsRow` component

* Add test to cover the case of changing PHP version

* Revert "Expose label in `SettingsRow` component"

This reverts commit bc37161.

* Update change PHP version test case

@fluiddot fluiddot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works as expected 🎊, nice work @danielbachhuber @derekblank 🏅 !

I added some comments that shouldn't block the PR but that I plan to address in a separate PR.

Additionally, I noticed a minor issue regarding the window size after we added this new element. As you can see in the screenshot, the settings tab's content now overflows and causes the content to scroll. If I'm not wrong, we've avoided in the past that this tab have a scroll, so we could consider increasing the minimum window height to do so.

Screenshot 2024-06-12 at 13 42 26

cc @matt-west

Comment thread src/components/content-tab-settings.tsx Outdated
// Empty strings account for legacy sites lacking a stored password.
const storedPassword = decodePassword( selectedSite.adminPassword ?? '' );
const password = storedPassword === '' ? 'password' : storedPassword;
const phpVersion = useGetPhpVersion( selectedSite );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the hook useGetPhpVersion is not necessary because the PHP version is already coming from the site details in selectedSite.

	const phpVersion = selectedSite.phpVersion ?? DEFAULT_PHP_VERSION;

Not sure if this approach has been followed based on the other hook useGetWpVersion. If so, the WordPress version needs to be retrieved from the WordPress files as it's not referenced in the site details. That's the main reason for needing that hook.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add these changes in a separate PR to avoid blocking this one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add these changes in a separate PR to avoid blocking this one.

#239

@matt-west

Copy link
Copy Markdown
Contributor

While we've tried to avoid scrolling on the settings screen in the past, we were always going to reach the point that it was needed. I’m happy with letting that screen scroll now.

@fluiddot

Copy link
Copy Markdown
Contributor

I wonder if we should warn the user about site restarting when changing the PHP version on a running site. This is not a destructive action but it might be unexpected by the user. WDYT?

@matt-west

Copy link
Copy Markdown
Contributor

@fluiddot I'm not sure that's necessary. I feel there's an expectation that changing the PHP version in that modal would apply the change right away.

@fluiddot fluiddot self-assigned this Jun 13, 2024
fluiddot added 2 commits June 13, 2024 16:25
* Remove `getPhpVersion` hook and IPC handler

* Use `??` operator instead of `||` when setting the php version

* Add inline comment in Jest setup

The comment clarifies why we need the polyfill.
Related to: #231 (comment)

* Update `ContentTabSettings` unit tests
* Bump default PHP version to `8.1`

This change is driven by the fact that version `8.0` already reached its end-of-life by 2024.
https://www.php.net/supported-versions.php

* Address failure in `createSite` unit test
@wojtekn

wojtekn commented Jun 17, 2024

Copy link
Copy Markdown
Contributor

While we've tried to avoid scrolling on the settings screen in the past, we were always going to reach the point that it was needed. I’m happy with letting that screen scroll now.

@matt-west it's okay, but it seems we need to make the scrollbar visible all the time, similarly to the sidebar. Now, the main content sidebar scrollbar appears only if the user starts scrolling.

@wojtekn
wojtekn merged commit ab0cc21 into trunk Jun 17, 2024
@wojtekn
wojtekn deleted the improve/php-version-picker branch June 17, 2024 08:59
@fluiddot

Copy link
Copy Markdown
Contributor

@matt-west it's okay, but it seems we need to make the scrollbar visible all the time, similarly to the sidebar. Now, the main content sidebar scrollbar appears only if the user starts scrolling.

FYI I've applied this fix in #255.

@lajennylove

Copy link
Copy Markdown

It works as expected 🎊, nice work @danielbachhuber @derekblank 🏅 !

I added some comments that shouldn't block the PR but that I plan to address in a separate PR.

Additionally, I noticed a minor issue regarding the window size after we added this new element. As you can see in the screenshot, the settings tab's content now overflows and causes the content to scroll. If I'm not wrong, we've avoided in the past that this tab have a scroll, so we could consider increasing the minimum window height to do so.

Screenshot 2024-06-12 at 13 42 26 cc @matt-west

Hey there guys!

I don't know if this is related to the new implementation regarding the PHP selector, but as soon as I tried to use it I found permission issues. I tried to chown the permissions but it was having the same issue anyway.

Screenshot 2024-06-17 at 8 26 10 p m

To replicate:

composer install
yarn 
yarn build
  • And then activate the theme, or just live preview it to avoid having issues.

This is the complete log that I got.

Warning: require(/var/www/html/wp-content/cache/acorn/framework/cache/packages.php): Failed to open stream: Permission denied in /var/www/html/wp-content/themes/sage-vite/vendor/illuminate/filesystem/Filesystem.php on line 123

Fatal error: Uncaught Error: Failed opening required '/var/www/html/wp-content/cache/acorn/framework/cache/packages.php' (include_path='.:') in /var/www/html/wp-content/themes/sage-vite/vendor/illuminate/filesystem/Filesystem.php:123 Stack trace: #0 /var/www/html/wp-content/themes/sage-vite/vendor/illuminate/filesystem/Filesystem.php(124): Illuminate\Filesystem\Filesystem::Illuminate\Filesystem\{closure}() #1 /var/www/html/wp-content/themes/sage-vite/vendor/roots/acorn/src/Illuminate/Foundation/PackageManifest.php(111): Illuminate\Filesystem\Filesystem->getRequire('/var/www/html/w...') #2 /var/www/html/wp-content/themes/sage-vite/vendor/roots/acorn/src/Illuminate/Foundation/PackageManifest.php(90): Illuminate\Foundation\PackageManifest->getManifest() #3 /var/www/html/wp-content/themes/sage-vite/vendor/roots/acorn/src/Illuminate/Foundation/PackageManifest.php(79): Illuminate\Foundation\PackageManifest->config('aliases') #4 /var/www/html/wp-content/themes/sage-vite/vendor/roots/acorn/src/Roots/Acorn/Bootstrap/RegisterFacades.php(25): Illuminate\Foundation\PackageManifest->aliases() #5 /var/www/html/wp-content/themes/sage-vite/vendor/roots/acorn/src/Illuminate/Foundation/Application.php(263): Roots\Acorn\Bootstrap\RegisterFacades->bootstrap(Object(Roots\Acorn\Application)) #6 /var/www/html/wp-content/themes/sage-vite/vendor/roots/acorn/src/Illuminate/Foundation/Http/Kernel.php(186): Illuminate\Foundation\Application->bootstrapWith(Array) #7 /var/www/html/wp-content/themes/sage-vite/vendor/roots/acorn/src/Roots/Acorn/Bootloader.php(187): Illuminate\Foundation\Http\Kernel->bootstrap(Object(Illuminate\Http\Request)) #8 /var/www/html/wp-content/themes/sage-vite/vendor/roots/acorn/src/Roots/Acorn/Bootloader.php(103): Roots\Acorn\Bootloader->bootHttp() #9 /var/www/html/wp-content/themes/sage-vite/functions.php(43): Roots\Acorn\Bootloader->boot() #10 /var/www/html/wp-settings.php(663): include('/var/www/html/w...') #11 /var/www/html/wp-config.php(96): require_once('/var/www/html/w...') #12 /var/www/html/wp-load.php(50): require_once('/var/www/html/w...') #13 /var/www/html/wp-admin/admin.php(34): require_once('/var/www/html/w...') #14 /var/www/html/wp-admin/customize.php(13): require_once('/var/www/html/w...') #15 {main} thrown in /var/www/html/wp-content/themes/sage-vite/vendor/illuminate/filesystem/Filesystem.php on line 123

I hope this is the right place to add this if not I can move it somewhere else.

Best regards.

@danielbachhuber

Copy link
Copy Markdown
Contributor Author

@lajennylove Can you open a new GitHub issue for the issue? Thanks!

@fluiddot

Copy link
Copy Markdown
Contributor

Thanks @lajennylove for reporting the issue. As Daniel mentioned, it would be great if you could open a GitHub issue with this information. Thanks 🙇 !

@lajennylove

Copy link
Copy Markdown

Hey @danielbachhuber and @fluiddot I already sent the report about the issue I hope it helps.

Thank you!

@fluiddot

Copy link
Copy Markdown
Contributor

Hey @danielbachhuber and @fluiddot I already sent the report about the issue I hope it helps.

Thank you!

Great, thank you @lajennylove for reporting the issue.

@lajennylove

Copy link
Copy Markdown

Hey @danielbachhuber and @fluiddot I already sent the report about the issue I hope it helps.
Thank you!

Great, thank you @lajennylove for reporting the issue.

Anytime!

wojtekn added a commit that referenced this pull request Jun 3, 2026
## Related issues

Closes ~35 open Dependabot security alerts on the repository.

## How AI was used in this PR

Claude identified which Dependabot alerts were fixable via `npm update`
(stale lockfile entries within existing semver ranges) vs. those
requiring direct dep bumps or overrides, then applied all the easy wins
in one shot.

## Proposed Changes

Updates transitive and direct dependencies to their patched versions to
close the majority of open Dependabot security alerts. All updates are
within the existing declared semver ranges of their parent packages — no
breaking changes expected.

| Package | From | To | Alerts closed |
|---------|------|----|---------------|
| `fast-uri` | 3.1.0 | 3.1.2 |
[#210](https://github.com/Automattic/studio/security/dependabot/210),
[#207](https://github.com/Automattic/studio/security/dependabot/207) |
| `@xmldom/xmldom` | 0.8.11 | 0.8.13 |
[#192](https://github.com/Automattic/studio/security/dependabot/192),
[#191](https://github.com/Automattic/studio/security/dependabot/191),
[#190](https://github.com/Automattic/studio/security/dependabot/190),
[#170](https://github.com/Automattic/studio/security/dependabot/170) |
| `brace-expansion` | 1.1.12 | 1.1.15 |
[#168](https://github.com/Automattic/studio/security/dependabot/168) |
| `qs` | 6.14.0 | 6.15.2 |
[#228](https://github.com/Automattic/studio/security/dependabot/228),
[#89](https://github.com/Automattic/studio/security/dependabot/89),
[#110](https://github.com/Automattic/studio/security/dependabot/110) |
| `ip-address` | 10.1.0 | 10.1.1 |
[#199](https://github.com/Automattic/studio/security/dependabot/199) |
| `basic-ftp` | 5.3.0 | 5.3.1 |
[#202](https://github.com/Automattic/studio/security/dependabot/202) |
| `ws` | 8.18.0 | 8.21.0 |
[#224](https://github.com/Automattic/studio/security/dependabot/224) |
| `protobufjs` | 7.5.5 | 7.6.2 |
[#221](https://github.com/Automattic/studio/security/dependabot/221),
[#220](https://github.com/Automattic/studio/security/dependabot/220),
[#217](https://github.com/Automattic/studio/security/dependabot/217),
[#216](https://github.com/Automattic/studio/security/dependabot/216),
[#219](https://github.com/Automattic/studio/security/dependabot/219),
[#218](https://github.com/Automattic/studio/security/dependabot/218),
[#215](https://github.com/Automattic/studio/security/dependabot/215),
[#225](https://github.com/Automattic/studio/security/dependabot/225) |
| `hono` | 4.12.7 | 4.12.23 |
[#211](https://github.com/Automattic/studio/security/dependabot/211),
[#208](https://github.com/Automattic/studio/security/dependabot/208),
[#204](https://github.com/Automattic/studio/security/dependabot/204),
[#203](https://github.com/Automattic/studio/security/dependabot/203),
[#188](https://github.com/Automattic/studio/security/dependabot/188),
[#185](https://github.com/Automattic/studio/security/dependabot/185),
[#184](https://github.com/Automattic/studio/security/dependabot/184),
[#183](https://github.com/Automattic/studio/security/dependabot/183),
[#182](https://github.com/Automattic/studio/security/dependabot/182),
[#181](https://github.com/Automattic/studio/security/dependabot/181),
[#209](https://github.com/Automattic/studio/security/dependabot/209) |
| `@hono/node-server` | 1.19.11 | 1.19.14 |
[#180](https://github.com/Automattic/studio/security/dependabot/180) |
| `lodash` | 4.17.23 | 4.18.1 |
[#172](https://github.com/Automattic/studio/security/dependabot/172),
[#171](https://github.com/Automattic/studio/security/dependabot/171) |
| `@babel/plugin-transform-modules-systemjs` | 7.27.1 | 7.29.7 |
[#212](https://github.com/Automattic/studio/security/dependabot/212) |
| `@anthropic-ai/sdk` | ^0.90.0 | ^0.91.1 |
[#197](https://github.com/Automattic/studio/security/dependabot/197),
[#196](https://github.com/Automattic/studio/security/dependabot/196) |

**Remaining open alerts** are blocked by exact-pinned third-party
packages (`@php-wasm/*`, `@mariozechner/pi-*`, `electron2appx`) or have
no upstream fix (`showdown`). Those require upstream releases to
resolve.

## Testing Instructions

- [ ] `npm run typecheck` passes
- [ ] `npm test` passes
- [ ] App starts and sites load normally

## Pre-merge Checklist

- [x] No direct dependency version constraints changed (all updates are
lockfile-only except `@anthropic-ai/sdk` range bump)
- [x] `@wp-playground/*` and `@php-wasm/*` pins untouched
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

7 participants