From 57789004e02bb18f29cbc71a4a1049abfe7b8d9f Mon Sep 17 00:00:00 2001 From: Brandon Payton Date: Fri, 26 Apr 2024 14:17:07 -0400 Subject: [PATCH 1/2] Add basic README to document WP Cloud website setup --- .../playground/website-deployment/README.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 packages/playground/website-deployment/README.md diff --git a/packages/playground/website-deployment/README.md b/packages/playground/website-deployment/README.md new file mode 100644 index 0000000000..a4a033b4e1 --- /dev/null +++ b/packages/playground/website-deployment/README.md @@ -0,0 +1,28 @@ +# Hosting playground.wordpress.net on WP Cloud + +This document covers our setup to host playground.wordpress.net on WP Cloud. + +## Web server configuration + +The WP Cloud platform is primarily focused on hosting WordPress. Since playground.wordpress.net is not a WordPress site and has some Playground-specific requirements, we had to do a number of things to get the site running as desired. + +WP Cloud uses Nginx which does not support the .htaccess files we used previously for: + +- rewriting URLs +- redirecting requests +- customizing response headers + +In order to customize these aspects for static files on WP Cloud, we did the following: + +- Configured the WP Cloud site to delegate requests for non-existent files to WordPress. +- Provided a `__wp__/index.php` file as a default target for Nginx. - Even though this is not a WordPress site, we can provide a `__wp__/index.php` file that Nginx will run as a fallback for non-existent files. The `__wp__/index.php` file is empty and simply exists so Nginx will invoke PHP. +- Added a `custom-redirects.php` file to implement special request handling. - WP Cloud invokes `/custom-redirects.php` (if it exists) at the beginning of every PHP run in order to provide custom request handling. We added this file to implement the rewrites, redirects, and custom headers that we used to get via htaccess. +- Set aside files that need special handling. - If we need custom treatment of static files, those files cannot be found by Nginx. Otherwise, Nginx will serve them directly without invoking PHP. For this reason, all files that need special treatment are set aside under `/files-to-serve-via-php/` + +## Deployment notes + +New website builds are pushed to the WP Cloud site via SSH. + +During deployment, we consult `custom-redirects-lib.php` about each file, and if it needs special treatment (e.g., URL rewrites, redirects, etc), it is set aside into the `/files-to-serve-via-php/` folder with its relative path otherwise preserved. For example, if a file `a/b/c/playground.png` requires special handling, it is moved to `/files-to-serve-via-php/a/b/c/playground.png`. Nginx will no longer find the file based on the request URI `a/b/c/playground.png` and will delegate the request to PHP, giving us a chance to customize how the file is served. + +At the end of the deployment process, the WP Cloud edge cache is purged. From 0e167c25db9341376671ef27162e4d03a024066e Mon Sep 17 00:00:00 2001 From: Brandon Payton Date: Fri, 26 Apr 2024 14:27:10 -0400 Subject: [PATCH 2/2] Document how secrets are set and consumed --- packages/playground/website-deployment/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/playground/website-deployment/README.md b/packages/playground/website-deployment/README.md index a4a033b4e1..6e19c6d73d 100644 --- a/packages/playground/website-deployment/README.md +++ b/packages/playground/website-deployment/README.md @@ -26,3 +26,7 @@ New website builds are pushed to the WP Cloud site via SSH. During deployment, we consult `custom-redirects-lib.php` about each file, and if it needs special treatment (e.g., URL rewrites, redirects, etc), it is set aside into the `/files-to-serve-via-php/` folder with its relative path otherwise preserved. For example, if a file `a/b/c/playground.png` requires special handling, it is moved to `/files-to-serve-via-php/a/b/c/playground.png`. Nginx will no longer find the file based on the request URI `a/b/c/playground.png` and will delegate the request to PHP, giving us a chance to customize how the file is served. At the end of the deployment process, the WP Cloud edge cache is purged. + +## Secrets + +Secrets are provided by a "Persistent Data" feature of WP Cloud and are set manually via a WP Cloud API. Once set, the secrets are synched to the site in an encrypted form which is accessed by `custom-redirects-lib.php` via the `Atomic_Persistent_Data`. Here is an [example of retrieving Slack-related secrets](https://github.com/WordPress/wordpress-playground/blob/776e8bbddecdde287ae7bb1d42d711dedf71f138/packages/playground/website-deployment/custom-redirects-lib.php#L186-L192).