From 004c995a847d6daf512fedccb5e79b050d5597ab Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Tue, 13 May 2025 16:27:31 -0500 Subject: [PATCH 01/27] EOD WIP --- .../get-started/stacks/wordpress/multisite.md | 243 ++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 sites/upsun/src/get-started/stacks/wordpress/multisite.md diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md new file mode 100644 index 0000000000..0c30a48fe3 --- /dev/null +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -0,0 +1,243 @@ +--- +title: Deploy WordPress Multisite on {{% vendor/name %}} +sidebarTitle: "WordPress Multisite" +weight: 1 +description: | + Complete the last required steps to successfully deploy a WordPress Multisite on Upsun. +--- + +{{< note theme="info" >}} + +Before you start, check out the [{{% vendor/name %}} demo app](https://console.upsun.com/projects/create-project) +and the main [Getting started guide](/get-started/here/_index.md). +These resources provide all the core concepts and common commands you need to know before using the following materials. + +{{< /note >}} + +For WordPress Multisite to successfully deploy and operate, **after completing the [Getting started guide](/get-started/here/_index.md)**, +you still need to add some required files and make a few changes to your {{% vendor/name %}} configuration. + +{{% guides/requirements name="WordPress" %}} + +{{< note theme="info" title="Assumptions" >}} + +There are many ways you can set up a [WordPress Multisite](https://developer.wordpress.org/advanced-administration/multisite/) or {{% vendor/name %}} project. +The instructions on this page were designed based on the following assumptions: + +- You selected **PHP** as your runtime, and **MariaDB** as a service during the Getting Started guide. It's also assumed that +while using the Getting Started guide you named the project `myapp`, which you will notice is the top-level key in all +configuration below. +- Your database relationship name is `mariadb` (the default) +- You have a working WordPress site based on either the [WordPress Composer](/get-started/stacks/wordpress/composer.html), +[Bedrock](https://docs.upsun.com/get-started/stacks/wordpress/bedrock.html), or +[WordPress Vanilla](/get-started/stacks/wordpress/vanilla.html) guides. +- WordPress is installed in the web/public root of the site and not in a subdirectory of its own (see notes at the end of this +guide for that scenario) +- You know if you are creating a +[subdirectory-based multisite or a sub/multi-domain based multisite](https://developer.wordpress.org/advanced-administration/multisite/prepare-network/#types-of-multisite-network). + +map_values(select(.primary == true and .type == "upstream" and .upstream == "app" )) | keys | .[0] | if (.[-1:] == "/") then (.[0:-1]) else . end +to_entries[] | select(.value.primary == true and .value.type == "upstream" and .value.upstream == "app") | if (.key[-1:] == "/") then (.key[0:-1]) else .key end + +{{< /note >}} + +## 1. Add rewrite rules to your root location + +If you are setting up a subdirectory-based multisite, the following rewrite rules are **required**. If you are unsure, +or if you think you might convert to a subdirectory-based multisite later, you can add these rules to a sub/multi-domain +multisite without any negative effects. + +Locate the `web:locations` section in your `.upsun/config.yaml` file and update the rules section for your root (`/`) +location as follows: + +```yaml {configFile="app"} +applications: + myapp: + + web: + locations: + "/": + + rules: + ^/license\.text$: + allow: false + ^/readme\.html$: + allow: false + '^/([_0-9a-zA-Z-]+/)?wp-(?[a-z\-]+).php$': + allow: true + scripts: true + passthru: '/wp-$wproot.php' + # Allows directory-based multisites to still access the wp-admin and wp-include locations + '^/([_0-9a-zA-Z-]+/)?(?wp-(admin|includes).*)': + allow: true + scripts: true + passthru: '/$adminrewrite' + '^/([_0-9a-zA-Z-]+)/wp-content/(?.*)': + allow: true + scripts: false + passthru: '/wp-content/$content' + expires: 1w +``` + +## 2. Update the database during the deploy hook + +The domain(s) of your multisite are stored in the database itself. This creates a challenge in a system like Upsun where +you often create [preview environments](/glossary.html#preview-environment) dynamically during development. To ensure +the database for your preview environments are updated with the correct domains, we have created a +[wp-cli package](https://github.com/upsun/wp-ms-dbu) to automate the process of updating the database with the preview +environment's unique domain name. + +To install the wp-cli package, locate the `build:` section and update it as follows: + +```yaml {configFile="app"} +applications: + myapp: + + hooks: + build: | + set -eux + wp package install upsun/wp-ms-dbu + wp package update upsun/wp-ms-dbu +``` +To instruct the package to update your database with the relevant domains for the preview environment, locate the +`deploy` section and update it as follows: + +```yaml {configFile="app"} +applications: + myapp: + + hooks: + deploy: | + set -eux + + PRODURL=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r '[.[] | select(.primary == true)] | first | .production_url') + if [ 'production' != "${PLATFORM_ENVIRONMENT_TYPE}" ] && wp site list --format=count --url="${PRODURL}" >/dev/null 2>&1; then + echo "Updating the database..."; + wp ms-dbu update --url="${PRODURL}" + else + echo "Database appears to already be updated. Skipping."; + fi + wp cache flush + wp core update-db +``` + + +## 3. Environment variables + +In order to process the domains, we need to be able to determine the default production domain. Upsun provides information +about all routes + +DOMAIN_CURRENT_SITE +MULTISITE_INSTALLED + +Some tasks need to be performed after the images for our application are built, +but before the newly built application can receive requests. +Therefore, the best time to launch them is during the [deploy hook](/learn/overview/build-deploy.md#deploy-steps). + +Such tasks include: + +- Flushing the object cache, which might have changed between current production and newly deployed changes +- Running the WordPress database update procedure, in case core is being updated with the newly deployed changes +- Running any due cron jobs + +To launch these tasks during the deploy hook, +locate the `deploy:` section (below the `build:` section).
+Update the `deploy:` section as follows: + +```yaml {configFile="app"} +applications: + myapp: + source: + root: "/" + type: 'php:8.3' + ... + hooks: + deploy: | + set -eux + # Flushes the object cache + wp cache flush + # Runs the WordPress database update procedure + wp core update-db + # Runs all due cron events + wp cron event run --due-now +``` + +## 6. Configure your default route + +Next, instruct the [router](learn/overview/structure.md#router) how to handle requests to your WordPress app. +To do so, locate the `routes:` section, and beneath it, the `"https://{default}/":` route. + +Update the route as follows: + +```yaml {configFile="app"} +applications: + myapp: + source: + root: "/" + type: 'php:8.3' + ... + +routes: + "https://{default}/": + type: upstream + upstream: "myapp:http" + cache: + enabled: true + cookies: + - '/^wordpress_*/' + - '/^wp-*/' +``` + +Matching the application name `myapp` with the `upstream` definition `myapp:http` is the most important setting to ensure at this stage. +If these strings aren't the same, the WordPress deployment will not succeed. + +## 7. Update your MariaDB service relationship + +You need to update the name used to represent the [relationship](/create-apps/app-reference/single-runtime-image.md#relationships) between your app and your MariaDB service. +To do so, locate the `relationships:` top-level property. +Update the relationship for the database service as follows: + +```yaml {configFile="app"} +applications: + myapp: + source: + root: "/" + type: 'php:8.3' + # ... + relationships: + database: "mariadb:mysql" +``` + +You can now commit all the changes made to `.upsun/config.yaml` and push to {{% vendor/name %}}. + + ```bash {location="Terminal"} + git add . + git commit -m "Add changes to complete my {{% vendor/name %}} configuration" + git push + ``` + + +## Further resources + +### Documentation + +- [PHP documentation](/languages/php/_index.md) + +- [Extensions](/languages/php/extensions.md) + +- [Performance tuning](/languages/php/tuning.md) + +- [PHP-FPM sizing](/languages/php/fpm.md) + +- [Authenticated Composer](/languages/php/composer-auth.md) + +### Community content + +- [PHP topics](https://support.platform.sh/hc/en-us/search?utf8=%E2%9C%93&query=php) +- [WordPress topics](https://support.platform.sh/hc/en-us/search?utf8=%E2%9C%93&query=wordpress) + +### Blogs + +- [To {{% vendor/name %}}, a WordPress migration story](https://upsun.com/blog/to-upsun-a-wordpress-migration-story/) + + From 4b1486ce6b561419ca19e98ff0e7413d2ffa3259 Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Tue, 13 May 2025 17:30:22 -0500 Subject: [PATCH 02/27] ok the REAL EOD WIP --- .../get-started/stacks/wordpress/multisite.md | 171 ++++++++++-------- 1 file changed, 94 insertions(+), 77 deletions(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index 0c30a48fe3..211e55cd9e 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -35,10 +35,6 @@ configuration below. guide for that scenario) - You know if you are creating a [subdirectory-based multisite or a sub/multi-domain based multisite](https://developer.wordpress.org/advanced-administration/multisite/prepare-network/#types-of-multisite-network). - -map_values(select(.primary == true and .type == "upstream" and .upstream == "app" )) | keys | .[0] | if (.[-1:] == "/") then (.[0:-1]) else . end -to_entries[] | select(.value.primary == true and .value.type == "upstream" and .value.upstream == "app") | if (.key[-1:] == "/") then (.key[0:-1]) else .key end - {{< /note >}} ## 1. Add rewrite rules to your root location @@ -124,98 +120,119 @@ applications: ## 3. Environment variables -In order to process the domains, we need to be able to determine the default production domain. Upsun provides information -about all routes +In order to process the domains, we need to be able to determine the default "parent" domain for the multisite. Upsun +provides information about all routes in the environment variable [`PLATFORM_ROUTES`](/development/variables/use-variables.html#use-provided-variables) +and we can use this information to determine the needed domain. In your `.environment` file, add the following: -DOMAIN_CURRENT_SITE -MULTISITE_INSTALLED +```bash {location=".environment"} +export SITE_ROUTES=$(echo $PLATFORM_ROUTES | base64 --decode) +export DOMAIN_CURRENT_SITE=$(echo $SITE_ROUTES | jq -r --arg app "${PLATFORM_APPLICATION_NAME}" 'map_values(select(.primary == true and .type == "upstream" and .upstream == $app )) | keys | .[0] | if (.[-1:] == "/") then (.[0:-1]) else . end') +``` -Some tasks need to be performed after the images for our application are built, -but before the newly built application can receive requests. -Therefore, the best time to launch them is during the [deploy hook](/learn/overview/build-deploy.md#deploy-steps). -Such tasks include: +## 4. wp-config.php -- Flushing the object cache, which might have changed between current production and newly deployed changes -- Running the WordPress database update procedure, in case core is being updated with the newly deployed changes -- Running any due cron jobs +Once our multisite has been set up, we need to expose additional pieces of information inside our `wp-config.php` file. +In your wp-config.php file, right above the section: -To launch these tasks during the deploy hook, -locate the `deploy:` section (below the `build:` section).
-Update the `deploy:` section as follows: +```php {location="wp-config.php"} +/** Absolute path to the WordPress directory. */ +if ( ! defined( 'ABSPATH' ) ) { + define( 'ABSPATH', dirname( __FILE__ ) . '/' ); +} +``` -```yaml {configFile="app"} -applications: - myapp: - source: - root: "/" - type: 'php:8.3' - ... - hooks: - deploy: | - set -eux - # Flushes the object cache - wp cache flush - # Runs the WordPress database update procedure - wp core update-db - # Runs all due cron events - wp cron event run --due-now +add the following: + +```php {location="wp-config.php"} +/** + * Multisite support + */ +define('WP_ALLOW_MULTISITE', true); //enables the Network setup panel in Tools +define('MULTISITE', false); //instructs WordPress to run in multisite mode + +if( MULTISITE && WP_ALLOW_MULTISITE) { + define('SUBDOMAIN_INSTALL', false); // does the instance contain subdirectory sites (false) or subdomain/multiple domain sites (true) + define('DOMAIN_CURRENT_SITE', filter_var(getenv('DOMAIN_CURRENT_SITE'),FILTER_VALIDATE_URL)); + define('PATH_CURRENT_SITE', '/'); //path to the WordPress site if it isn't the root of the site (e.g. https://foo.com/blog/) + define('SITE_ID_CURRENT_SITE', 1); //main/primary site ID + define('BLOG_ID_CURRENT_SITE', 1); //main/primary/parent blog ID + + /** + * we have a sub/multidomain multisite, and the site currently being requested is not the default domain, so we'll + * need to set COOKIE_DOMAIN to the domain being requested + */ + if (SUBDOMAIN_INSTALL && $site_host !== DOMAIN_CURRENT_SITE) { + define('COOKIE_DOMAIN',$site_host); + } +} ``` +where `SUBDOMAIN_INSTALL` is set to `true` if your multisite is a sub/multi-domain site, or `false` if you will be +setting up a subdirectory-based multisite. Note that `MULTISITE` is currently set to `false`; we will update his once +the database has finished being set up for the multisite. + +{{< note theme="info" title="Variable placement" >}} +For the values `SUBDOMAIN_INSTALL`, `MULTISITE`, and `WP_ALLOW_MULTISITE`, including them in the wp-config.php file is +perfectly acceptable. However, if you will be creating multiple multisites, and starting from a canonical repository, +I would suggest defining these values as environment variables, and updating these sections in wp-config.php to +retrieve the information from these environment variables +(e.g. `define('SUBDOMAIN_INSTALL', filter_var(getenv('SUBDOMAIN_INSTALL'),FILTER_VALIDATE_BOOLEAN));`). This allows you +to change the behavior of a specific instance of the codebase by changing these variables instead of having to make +changes directly to wp-config.php. +{{< /note >}} + +## 5. Commit and push +You can now commit all the changes made above `.upsun/config.yaml` and push to {{% vendor/name %}}. -## 6. Configure your default route + ```bash {location="Terminal"} + git add wp-config.php .environment .upsun/config.yaml + git commit -m "Add changes to begin setup of my {{% vendor/name %}} WordPress multisite" + {{% vendor/cli %}} push -y + ``` -Next, instruct the [router](learn/overview/structure.md#router) how to handle requests to your WordPress app. -To do so, locate the `routes:` section, and beneath it, the `"https://{default}/":` route. + -Update the route as follows: +## 6. Network (Multisite) Setup +Adding `define('WP_ALLOW_MULTISITE', true);` will enable the **Network Setup** item in your **Tools menu**. Use that +menu item to go to the **Create a Network of WordPress Sites** screen. Follow the instructions on this screen and click +the **Install** button. You can ignore the instructions on the resulting screen. -```yaml {configFile="app"} -applications: - myapp: - source: - root: "/" - type: 'php:8.3' - ... - -routes: - "https://{default}/": - type: upstream - upstream: "myapp:http" - cache: - enabled: true - cookies: - - '/^wordpress_*/' - - '/^wp-*/' -``` +{{< note >}} +Alternatively, you can access a terminal session in the app container (`{{% vendor/cli %}} ssh`), and use +`wp core multisite-convert` to install the multisite. +{{< /note >}} -Matching the application name `myapp` with the `upstream` definition `myapp:http` is the most important setting to ensure at this stage. -If these strings aren't the same, the WordPress deployment will not succeed. +## 7. Final change to wp-config.php +Return to your wp-config.php file and change -## 7. Update your MariaDB service relationship +```php {location="wp-config.php"} +define('MULTISITE', false); +``` +to +```php {location="wp-config.php"} +define('MULTISITE', true); +``` -You need to update the name used to represent the [relationship](/create-apps/app-reference/single-runtime-image.md#relationships) between your app and your MariaDB service. -To do so, locate the `relationships:` top-level property. -Update the relationship for the database service as follows: +Add and commit the changes, and push to {{% vendor/name %}}: -```yaml {configFile="app"} -applications: - myapp: - source: - root: "/" - type: 'php:8.3' - # ... - relationships: - database: "mariadb:mysql" +```shell {location="Terminal"} +git add wp-config.php +git commit -m "set WordPress to run in multisite mode." +{{% vendor/cli %}} push -y ``` -You can now commit all the changes made to `.upsun/config.yaml` and push to {{% vendor/name %}}. +Once the site has finished deploying, you can return the Network Admin --> Sites area of wp-admin and begin adding your +sites. - ```bash {location="Terminal"} - git add . - git commit -m "Add changes to complete my {{% vendor/name %}} configuration" - git push - ``` +## FOR WEDNESDAY: +1. Show the wp-cli package updating the database for a preview environment? +2. Discuss multi domain mapping? +3. Create a separate collection of files where you use env vars instead of doing it directly in wp-config.php? +4. Discuss changes needed if you install wordpress in its own directory? ## Further resources From ecc7ee181f39e92d365dc7c874f849b915db0024 Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Fri, 16 May 2025 12:39:55 -0500 Subject: [PATCH 03/27] more WIP changes --- sites/upsun/src/get-started/stacks/wordpress/multisite.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index 211e55cd9e..b83ba46cc9 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -122,7 +122,8 @@ applications: In order to process the domains, we need to be able to determine the default "parent" domain for the multisite. Upsun provides information about all routes in the environment variable [`PLATFORM_ROUTES`](/development/variables/use-variables.html#use-provided-variables) -and we can use this information to determine the needed domain. In your `.environment` file, add the following: +and we can use this information to determine the needed domain. These values will are used in later in the +`wp-config.php` file. In your `.environment` file, add the following: ```bash {location=".environment"} export SITE_ROUTES=$(echo $PLATFORM_ROUTES | base64 --decode) From b64a5704c30d3766507c7a882ef25dfa35d783c5 Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Fri, 16 May 2025 16:09:49 -0500 Subject: [PATCH 04/27] updates to the composer based guide and more work on the multisite guide --- .../get-started/stacks/wordpress/composer.md | 57 +++++++++++------ .../get-started/stacks/wordpress/multisite.md | 61 ++++++++----------- 2 files changed, 64 insertions(+), 54 deletions(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/composer.md b/sites/upsun/src/get-started/stacks/wordpress/composer.md index 93230f66ab..416ba14f6a 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/composer.md +++ b/sites/upsun/src/get-started/stacks/wordpress/composer.md @@ -148,6 +148,9 @@ To set one up, follow these steps: mount location accordingly. {{< /note >}} +## 3. Install the WP-CLI +@todo for Monday, add composer and wp-cli bundle at step 3. + ## 4. Install dependencies during the build hook To ensure your Composer dependencies are installed during the [build stage](/learn/overview/build-deploy.md#the-build), @@ -235,30 +238,46 @@ routes: Matching the application name `myapp` with the `upstream` definition `myapp:http` is the most important setting to ensure at this stage. If these strings aren't the same, the WordPress deployment will not succeed. -## 7. Update your MariaDB service relationship +## 7. Update the `.environment` file -You need to update the name used to represent the [relationship](/create-apps/app-reference/single-runtime-image.md#relationships) between your app and your MariaDB service. -To do so, locate the `relationships:` top-level property. -Update the relationship for the database service as follows: +We need to add a few environment variables that will be used inside the `wp-config.php` file we added previously. +Open the `.environment` file. Just after the other database-related variables, add: -```yaml {configFile="app"} -applications: - myapp: - source: - root: "/" - type: 'php:8.3' - # ... - relationships: - database: "mariadb:mysql" +```bash {location=".environment"} +export DB_NAME="$DB_PATH" ``` -You can now commit all the changes made to `.upsun/config.yaml` and push to {{% vendor/name %}}. +Add a blank line or two and add the following: - ```bash {location="Terminal"} - git add . - git commit -m "Add changes to complete my {{% vendor/name %}} configuration" - git push - ``` +```bash {location=".environment"} +# Routes, URLS, and primary domain +export SITE_ROUTES=$(echo $PLATFORM_ROUTES | base64 --decode) +export UPSTREAM_URLS=$(echo $SITE_ROUTES | jq -r --arg app "${PLATFORM_APPLICATION_NAME}" 'map_values(select(.type == "upstream" and .upstream == $app )) | keys') +export DOMAIN_CURRENT_SITE=$(echo $SITE_ROUTES | jq -r --arg app "${PLATFORM_APPLICATION_NAME}" 'map_values(select(.primary == true and .type == "upstream" and .upstream == $app )) | keys | .[0] | if (.[-1:] == "/") then (.[0:-1]) else . end') +``` + + +## 9. Commit and push + +You can now commit all the changes made to `.upsun/config.yaml` and `.environment` and push to {{% vendor/name %}}. + + ```bash {location="Terminal"} + git add . + git commit -m "Add changes to complete my upsun configuration" + git push + ``` ## Further resources diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index b83ba46cc9..ccd5c5bd65 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -15,14 +15,15 @@ These resources provide all the core concepts and common commands you need to kn {{< /note >}} For WordPress Multisite to successfully deploy and operate, **after completing the [Getting started guide](/get-started/here/_index.md)**, -you still need to add some required files and make a few changes to your {{% vendor/name %}} configuration. +and have a working WordPress site based on one of the other WordPress guides see **Assumptions**, you still need to make +a few changes to your {{% vendor/name %}} configuration. {{% guides/requirements name="WordPress" %}} {{< note theme="info" title="Assumptions" >}} -There are many ways you can set up a [WordPress Multisite](https://developer.wordpress.org/advanced-administration/multisite/) or {{% vendor/name %}} project. -The instructions on this page were designed based on the following assumptions: +There are many ways you can set up a [WordPress Multisite](https://developer.wordpress.org/advanced-administration/multisite/) +or {{% vendor/name %}} project. The instructions on this page were designed based on the following assumptions: - You selected **PHP** as your runtime, and **MariaDB** as a service during the Getting Started guide. It's also assumed that while using the Getting Started guide you named the project `myapp`, which you will notice is the top-level key in all @@ -92,6 +93,7 @@ applications: hooks: build: | set -eux + composer install --prefer-dist --optimize-autoloader --apcu-autoloader --no-progress --no-ansi --no-interaction wp package install upsun/wp-ms-dbu wp package update upsun/wp-ms-dbu ``` @@ -105,8 +107,8 @@ applications: hooks: deploy: | set -eux - - PRODURL=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r '[.[] | select(.primary == true)] | first | .production_url') + # we need the main production url + PRODURL=$($PLATFORM_ROUTES | base64 --decode | jq -r --arg app "${PLATFORM_APPLICATION_NAME}" '[.[] | select(.primary == true and .type == "upstream" and .upstream == $app )] | first | .production_url') if [ 'production' != "${PLATFORM_ENVIRONMENT_TYPE}" ] && wp site list --format=count --url="${PRODURL}" >/dev/null 2>&1; then echo "Updating the database..."; wp ms-dbu update --url="${PRODURL}" @@ -118,20 +120,7 @@ applications: ``` -## 3. Environment variables - -In order to process the domains, we need to be able to determine the default "parent" domain for the multisite. Upsun -provides information about all routes in the environment variable [`PLATFORM_ROUTES`](/development/variables/use-variables.html#use-provided-variables) -and we can use this information to determine the needed domain. These values will are used in later in the -`wp-config.php` file. In your `.environment` file, add the following: - -```bash {location=".environment"} -export SITE_ROUTES=$(echo $PLATFORM_ROUTES | base64 --decode) -export DOMAIN_CURRENT_SITE=$(echo $SITE_ROUTES | jq -r --arg app "${PLATFORM_APPLICATION_NAME}" 'map_values(select(.primary == true and .type == "upstream" and .upstream == $app )) | keys | .[0] | if (.[-1:] == "/") then (.[0:-1]) else . end') -``` - - -## 4. wp-config.php +## 3. wp-config.php Once our multisite has been set up, we need to expose additional pieces of information inside our `wp-config.php` file. In your wp-config.php file, right above the section: @@ -172,17 +161,7 @@ where `SUBDOMAIN_INSTALL` is set to `true` if your multisite is a sub/multi-doma setting up a subdirectory-based multisite. Note that `MULTISITE` is currently set to `false`; we will update his once the database has finished being set up for the multisite. -{{< note theme="info" title="Variable placement" >}} -For the values `SUBDOMAIN_INSTALL`, `MULTISITE`, and `WP_ALLOW_MULTISITE`, including them in the wp-config.php file is -perfectly acceptable. However, if you will be creating multiple multisites, and starting from a canonical repository, -I would suggest defining these values as environment variables, and updating these sections in wp-config.php to -retrieve the information from these environment variables -(e.g. `define('SUBDOMAIN_INSTALL', filter_var(getenv('SUBDOMAIN_INSTALL'),FILTER_VALIDATE_BOOLEAN));`). This allows you -to change the behavior of a specific instance of the codebase by changing these variables instead of having to make -changes directly to wp-config.php. -{{< /note >}} - -## 5. Commit and push +## 4. Commit and push You can now commit all the changes made above `.upsun/config.yaml` and push to {{% vendor/name %}}. ```bash {location="Terminal"} @@ -196,7 +175,7 @@ map_values(select(.primary == true and .type == "upstream" and .upstream == "app to_entries[] | select(.value.primary == true and .value.type == "upstream" and .value.upstream == "app") | if (.key[-1:] == "/") then (.key[0:-1]) else .key end --> -## 6. Network (Multisite) Setup +## 5. Network (Multisite) Setup Adding `define('WP_ALLOW_MULTISITE', true);` will enable the **Network Setup** item in your **Tools menu**. Use that menu item to go to the **Create a Network of WordPress Sites** screen. Follow the instructions on this screen and click the **Install** button. You can ignore the instructions on the resulting screen. @@ -206,7 +185,7 @@ Alternatively, you can access a terminal session in the app container (`{{% vend `wp core multisite-convert` to install the multisite. {{< /note >}} -## 7. Final change to wp-config.php +## 6. Final change to wp-config.php Return to your wp-config.php file and change ```php {location="wp-config.php"} @@ -228,12 +207,24 @@ git commit -m "set WordPress to run in multisite mode." Once the site has finished deploying, you can return the Network Admin --> Sites area of wp-admin and begin adding your sites. -## FOR WEDNESDAY: + ## Further resources From 133c4b7057934ea77e7e4afc8a95cfd06e28ccd2 Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Fri, 16 May 2025 19:20:21 -0500 Subject: [PATCH 05/27] correction to line we add to wp-config.php --- sites/upsun/src/get-started/stacks/wordpress/multisite.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index ccd5c5bd65..c38ff3ad93 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -108,7 +108,7 @@ applications: deploy: | set -eux # we need the main production url - PRODURL=$($PLATFORM_ROUTES | base64 --decode | jq -r --arg app "${PLATFORM_APPLICATION_NAME}" '[.[] | select(.primary == true and .type == "upstream" and .upstream == $app )] | first | .production_url') + PRODURL=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r --arg app "${PLATFORM_APPLICATION_NAME}" '[.[] | select(.primary == true and .type == "upstream" and .upstream == $app )] | first | .production_url') if [ 'production' != "${PLATFORM_ENVIRONMENT_TYPE}" ] && wp site list --format=count --url="${PRODURL}" >/dev/null 2>&1; then echo "Updating the database..."; wp ms-dbu update --url="${PRODURL}" @@ -143,7 +143,7 @@ define('MULTISITE', false); //instructs WordPress to run in multisite mode if( MULTISITE && WP_ALLOW_MULTISITE) { define('SUBDOMAIN_INSTALL', false); // does the instance contain subdirectory sites (false) or subdomain/multiple domain sites (true) - define('DOMAIN_CURRENT_SITE', filter_var(getenv('DOMAIN_CURRENT_SITE'),FILTER_VALIDATE_URL)); + define('DOMAIN_CURRENT_SITE', parse_url(filter_var(getenv('DOMAIN_CURRENT_SITE'),FILTER_VALIDATE_URL),PHP_URL_HOST)); define('PATH_CURRENT_SITE', '/'); //path to the WordPress site if it isn't the root of the site (e.g. https://foo.com/blog/) define('SITE_ID_CURRENT_SITE', 1); //main/primary site ID define('BLOG_ID_CURRENT_SITE', 1); //main/primary/parent blog ID @@ -212,6 +212,7 @@ sites. 1. Show the wp-cli package updating the database for a preview environment? 2. Discuss multi domain mapping? +3. Update step #2 and change the deploy hook to use map_values() 3. Discuss changes needed if you install wordpress in its own directory? <-- do this in a blog post @todo put this in a blog post as well From 215731bf2552e264f5035cb3f2030ea21ce8c433 Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Mon, 19 May 2025 10:04:07 -0500 Subject: [PATCH 06/27] Update sites/upsun/src/get-started/stacks/wordpress/multisite.md Co-authored-by: Kemi Elizabeth <97071326+Kemi-Elizabeth@users.noreply.github.com> --- sites/upsun/src/get-started/stacks/wordpress/multisite.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index c38ff3ad93..ec2e3c1ec8 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -14,7 +14,9 @@ These resources provide all the core concepts and common commands you need to kn {{< /note >}} -For WordPress Multisite to successfully deploy and operate, **after completing the [Getting started guide](/get-started/here/_index.md)**, +You will need to make a few changes to your {{% vendor/name %}} configuration for WordPress Multisite to successfully deploy and operate. + +Please note that these changes must only be made **after completing the [Getting started guide](/get-started/here/_index.md)**. Once the changes are made, you will have a working WordPress site (see **Assumptions** to read the WordPress guides and understand what your working WordPress site will be based on). and have a working WordPress site based on one of the other WordPress guides see **Assumptions**, you still need to make a few changes to your {{% vendor/name %}} configuration. From 27d457894b7f82fa646c1f0b82b84292205b9d6e Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Mon, 19 May 2025 10:04:14 -0500 Subject: [PATCH 07/27] Update sites/upsun/src/get-started/stacks/wordpress/multisite.md Co-authored-by: Kemi Elizabeth <97071326+Kemi-Elizabeth@users.noreply.github.com> --- sites/upsun/src/get-started/stacks/wordpress/multisite.md | 1 - 1 file changed, 1 deletion(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index ec2e3c1ec8..25e3cfadba 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -18,7 +18,6 @@ You will need to make a few changes to your {{% vendor/name %}} configuration fo Please note that these changes must only be made **after completing the [Getting started guide](/get-started/here/_index.md)**. Once the changes are made, you will have a working WordPress site (see **Assumptions** to read the WordPress guides and understand what your working WordPress site will be based on). and have a working WordPress site based on one of the other WordPress guides see **Assumptions**, you still need to make -a few changes to your {{% vendor/name %}} configuration. {{% guides/requirements name="WordPress" %}} From 68b021f6befbd8f016abf0dc91cb2049b48aeb73 Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Mon, 19 May 2025 10:04:22 -0500 Subject: [PATCH 08/27] Update sites/upsun/src/get-started/stacks/wordpress/multisite.md Co-authored-by: Kemi Elizabeth <97071326+Kemi-Elizabeth@users.noreply.github.com> --- sites/upsun/src/get-started/stacks/wordpress/multisite.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index 25e3cfadba..cb97b42c26 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -24,7 +24,7 @@ and have a working WordPress site based on one of the other WordPress guides see {{< note theme="info" title="Assumptions" >}} There are many ways you can set up a [WordPress Multisite](https://developer.wordpress.org/advanced-administration/multisite/) -or {{% vendor/name %}} project. The instructions on this page were designed based on the following assumptions: +or {{% vendor/name %}} project. The instructions on this page are based on the following assumptions: - You selected **PHP** as your runtime, and **MariaDB** as a service during the Getting Started guide. It's also assumed that while using the Getting Started guide you named the project `myapp`, which you will notice is the top-level key in all From 768fd36ed826a846734c898ca1634b8448a125e9 Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Mon, 19 May 2025 10:04:31 -0500 Subject: [PATCH 09/27] Update sites/upsun/src/get-started/stacks/wordpress/multisite.md Co-authored-by: Kemi Elizabeth <97071326+Kemi-Elizabeth@users.noreply.github.com> --- sites/upsun/src/get-started/stacks/wordpress/multisite.md | 1 - 1 file changed, 1 deletion(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index cb97b42c26..d5553b9933 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -17,7 +17,6 @@ These resources provide all the core concepts and common commands you need to kn You will need to make a few changes to your {{% vendor/name %}} configuration for WordPress Multisite to successfully deploy and operate. Please note that these changes must only be made **after completing the [Getting started guide](/get-started/here/_index.md)**. Once the changes are made, you will have a working WordPress site (see **Assumptions** to read the WordPress guides and understand what your working WordPress site will be based on). -and have a working WordPress site based on one of the other WordPress guides see **Assumptions**, you still need to make {{% guides/requirements name="WordPress" %}} From 0c21ad840eb93614db1fe67c30e3f103edaed5d5 Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Mon, 19 May 2025 10:50:51 -0500 Subject: [PATCH 10/27] corrects typo --- sites/upsun/src/get-started/stacks/wordpress/multisite.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index d5553b9933..a46e52482f 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -14,7 +14,7 @@ These resources provide all the core concepts and common commands you need to kn {{< /note >}} -You will need to make a few changes to your {{% vendor/name %}} configuration for WordPress Multisite to successfully deploy and operate. +You will need to make a few changes to your {{% vendor/name %}} configuration for WordPress Multisite to successfully deploy and operate. Please note that these changes must only be made **after completing the [Getting started guide](/get-started/here/_index.md)**. Once the changes are made, you will have a working WordPress site (see **Assumptions** to read the WordPress guides and understand what your working WordPress site will be based on). @@ -158,7 +158,7 @@ if( MULTISITE && WP_ALLOW_MULTISITE) { } ``` where `SUBDOMAIN_INSTALL` is set to `true` if your multisite is a sub/multi-domain site, or `false` if you will be -setting up a subdirectory-based multisite. Note that `MULTISITE` is currently set to `false`; we will update his once +setting up a subdirectory-based multisite. Note that `MULTISITE` is currently set to `false`; we will update this once the database has finished being set up for the multisite. ## 4. Commit and push From 2dcecab2ab65c812af26ae86695908ec8a942e5b Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Mon, 19 May 2025 13:13:36 -0500 Subject: [PATCH 11/27] adds a rule for docs.upsun.com to rewrite requests for favicon.ico to the correct location --- .platform/applications.yaml | 4 ++++ sites/upsun/static/favicon.ico | Bin 0 -> 15406 bytes 2 files changed, 4 insertions(+) create mode 100644 sites/upsun/static/favicon.ico diff --git a/.platform/applications.yaml b/.platform/applications.yaml index eda19cb2e8..9d7a89089a 100644 --- a/.platform/applications.yaml +++ b/.platform/applications.yaml @@ -127,6 +127,10 @@ \.txt$: headers: Content-Type: "text/plain; charset=UTF-8" + '^/favicon.ico$': + allow: true + passthru: '/images/favicon.ico' + disk: 1024 diff --git a/sites/upsun/static/favicon.ico b/sites/upsun/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..ab2565cc7cad392ce85fe7feb2df89fdf2b488a1 GIT binary patch literal 15406 zcmeI2Tc{OP7=Xu=E*7PwhGcn63ttK!Dv5k3i;4;|Dd>)ckwHO*1*US2mQg|wMf6Yz znOaa@BI~Jwh=eXknL$^J@FC5zAi8PR_u*bJj&t9$k6H7>$J(>j`Y-dZ%dDAmqG(7o zG#W7?qU?+242z<3qA2R?+jl*AWE3r@ZpxHS`{_}%adZ?-rVlD;?5n3Zl;jkGoe!(w zc~}4wpp4v0r{Cf41b=X?ogt7V>L&G)*9)_hslNy=@9-k!UQmBsr_Q#Ep-66_L(=c< z1xnsmU}K8@2eJ0F9GK@l9nPaEE2!z3*g9H`j>aesrG9U_JGJLGWXo z8#4N8V+lBxO~_n~{06~yC_P6Rb5njWb%5wQ_{%DNPWM8_VKnW&lW}-P=*2U=%o#Mq zvbc)`IDW3#B&()q#MRF1y()@o*z4u=vp3gsrG#itOlsoNPGW3^~(9gQ}uS)2KF85{l_nsbx!$Zed z>3!=vYtOc=tQ<$j9iYE7wo<KL#nZ2e;TqEhc5Waw{IGmRQFbaApzQ?+k z&FSDe@R?U;f2Uh3Z3fy5m;t|&Oo3U@ekUObt+W|vGw@%}fae6ir+H5CeP?`!ag?Ls zXz=X!Zxds_0DKo;4zI(9@MQEoH#zYooVBVn+`xX*;wApX58#8{<#8yiz$uEujiEO^D+1Z z^5Ut}_A545fMeSWG4IA+C$=g&EAioXf+oeBIA?m1_vF1f4*k&NdT^~aIp32pC$E3N z-!y1S{NCaFbrJ6OuEo8OjLEw1!9GQHY<~fo5}&7I3K&QGt?&lyfn@ydv+k95z{yZ# z&*!!K#bAhj7J}oRmiurow)qWa84OlzxXKmRwy}p8%a)I#)8rb>4KkzA99{wDy=>f} z-%sdV3kUN&=RWN^%bPPH-ejrHt8hFVEb-ggcaV&&?Dfy+o^h~($FFmzPVVFPH>-#7 z55;yKb7_yqQs?*50w4OXBjZu}6#Uy{7M_QW>5?Tm_VxP>oC;ONXUrDJ%jqk$ce{_T zDDbhB_CBa8J|EwLy!bz({luz z*sb@h*Iq(r((dpOQ7axO-E zcZ%EZ Date: Mon, 19 May 2025 16:13:32 -0500 Subject: [PATCH 12/27] updates some pieces due to alignment, adds note for vanilla users --- sites/upsun/src/get-started/stacks/wordpress/multisite.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index a46e52482f..383b928fc6 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -97,6 +97,12 @@ applications: wp package install upsun/wp-ms-dbu wp package update upsun/wp-ms-dbu ``` + +{{< note theme="info">}} +If you created your site based on the WordPress Vanilla guide, only add the lines above that start with `wp package` +(i.e. skip the `composer install` line). +{{< /note >}} + To instruct the package to update your database with the relevant domains for the preview environment, locate the `deploy` section and update it as follows: From f60fdecab1ad088e069223595274082071a0c801 Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Mon, 19 May 2025 16:13:59 -0500 Subject: [PATCH 13/27] aligns the two guides --- .../get-started/stacks/wordpress/composer.md | 63 +++++++----- .../get-started/stacks/wordpress/vanilla.md | 96 ++++++++++++------- 2 files changed, 103 insertions(+), 56 deletions(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/composer.md b/sites/upsun/src/get-started/stacks/wordpress/composer.md index 416ba14f6a..4e02d48245 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/composer.md +++ b/sites/upsun/src/get-started/stacks/wordpress/composer.md @@ -34,12 +34,14 @@ The instructions on this page were designed based on the following assumptions: To ensure you have all the required files and directories in your project, follow these steps: -1. Copy the following files from the [WordPress Composer template](https://github.com/platformsh-templates/wordpress-composer/) +1. Copy the following files from the [WordPress Composer Example Snippets](https://github.com/upsun/snippets/tree/main/examples/wordpress-composer) and add them to the root of your project: - - The [composer.json](https://raw.githubusercontent.com/platformsh-templates/wordpress-composer/61da65da21039b280b588642cd329a2eb253e472/composer.json) file declares project dependencies and specifies project settings and metadata for [Composer](https://getcomposer.org/) to use - - The [wp-cli.yml](https://github.com/platformsh-templates/wordpress-composer/blob/61da65da21039b280b588642cd329a2eb253e472/wp-cli.yml) file contains the configuration values, related to your site, for the [WordPress CLI](https://wp-cli.org/) to use - - The [wp-config.php](https://github.com/platformsh-templates/wordpress-composer/blob/61da65da21039b280b588642cd329a2eb253e472/wp-config.php) file contains your site's base configuration details, such as database connection information + - The [composer.json](https://raw.githubusercontent.com/upsun/snippets/refs/heads/main/examples/wordpress-composer/composer.json) file declares project dependencies and specifies project settings and metadata for [Composer](https://getcomposer.org/) to use + - The [wp-cli.yml](https://raw.githubusercontent.com/upsun/snippets/refs/heads/main/examples/wordpress-composer/wp-cli.yml) file contains the configuration values, related to your site, for the [WordPress CLI](https://wp-cli.org/) to use + - The [.environment](https://raw.githubusercontent.com/upsun/snippets/refs/heads/main/examples/wordpress-composer/.environment) file maps and creates environment variables to be used in `wp-config.php` + - The [wp-config.php](https://raw.githubusercontent.com/upsun/snippets/refs/heads/main/examples/wordpress-composer/wp-config.php) file contains your site's base configuration details, such as database connection information + 2. Optional: To support non-public plugins, add a `plugins` directory to your project. To ensure Git tracks empty folders, add a `plugins/.gitkeep` file as well. @@ -48,16 +50,13 @@ To ensure Git tracks empty folders, add a `plugins/.gitkeep` file as well. ```bash {location="Terminal"} git add . - git commit -m "Add files and directory" - git push + git commit -m "Adds initial WordPress and Upsun configuration files" ``` -Now that you have pushed all the necessary files and directories to Upsun, -make the following changes to your `./.upsun/config.yaml` file. - ## 2. Configure your root location - -Locate the `web:locations` section and update the root (`/`) location as follows: +Now that we have added the initial set of files to our repository, we need to make some additional modifications to the +Upsun configuration, so Upsun knows how to handle certain requests. Locate the `web:locations` section in the +`.upsun/config.yaml` file and update the root (`/`) location as follows: ```yaml {configFile="app"} applications: @@ -136,7 +135,7 @@ To set one up, follow these steps: source: root: "/" type: 'php:8.3' - ... + mounts: "wordpress/wp-content/uploads": source: storage @@ -148,10 +147,30 @@ To set one up, follow these steps: mount location accordingly. {{< /note >}} -## 3. Install the WP-CLI -@todo for Monday, add composer and wp-cli bundle at step 3. +## 4. Install the WP-CLI +To ensure we are able to perform tasks later in the deployment stage (e.g. updating the database, flushing cache, etc.) +we need to make sure the [wp-cli](https://wp-cli.org/) utility is a dependency of the application container. While still +in the `.upsun/config.yaml` file, locate the `dependencies.php` section, and add the following: + +```yaml {configFile="app"} +applications: + myapp: + source: + root: "/" + type: 'php:8.3' + + dependencies: + php: + composer/composer: "^2" + wp-cli/wp-cli-bundle: "^2.4" +``` + +{{< note >}} +It is possible the `dependencies` section is commented out. When uncommenting, pay attention to the indentation and that +the `dependencies` key aligns with other sibling keys (e.g. `build`, `hooks`, etc.) +{{< /note >}} -## 4. Install dependencies during the build hook +## 5. Install dependencies during the build hook To ensure your Composer dependencies are installed during the [build stage](/learn/overview/build-deploy.md#the-build), locate the `build:` section (below the `hooks:` section).
@@ -241,13 +260,8 @@ If these strings aren't the same, the WordPress deployment will not succeed. ## 7. Update the `.environment` file We need to add a few environment variables that will be used inside the `wp-config.php` file we added previously. -Open the `.environment` file. Just after the other database-related variables, add: - -```bash {location=".environment"} -export DB_NAME="$DB_PATH" -``` - -Add a blank line or two and add the following: +Open the `.environment` file. Just after the other database-related variables, add a blank line or two and add the +following: ```bash {location=".environment"} # Routes, URLS, and primary domain @@ -276,9 +290,12 @@ You can now commit all the changes made to `.upsun/config.yaml` and `.environmen ```bash {location="Terminal"} git add . git commit -m "Add changes to complete my upsun configuration" - git push + {{% vendor/cli %}} push ``` +## 10. Install WordPress +Once {{% vendor/name %}} has completed building and deploying your project, it will provide the list of routes assigned +to your project. You can now visit your site and complete the WordPress installation as you normally would. ## Further resources diff --git a/sites/upsun/src/get-started/stacks/wordpress/vanilla.md b/sites/upsun/src/get-started/stacks/wordpress/vanilla.md index 02f1633755..96d34c3a6b 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/vanilla.md +++ b/sites/upsun/src/get-started/stacks/wordpress/vanilla.md @@ -24,7 +24,7 @@ you still need to add some required files and make a few changes to your {{% ven There are many ways you can set up a WordPress site or {{% vendor/name %}} project. The instructions on this page were designed based on the following assumptions: -- You selected PHP as your runtime, and MariaDB as a service during the Getting Started guide. It's also assumed that +- You selected **PHP** as your runtime, and **MariaDB** as a service during the Getting Started guide. It's also assumed that while using the Getting Started guide you named the project `myapp`, which you will notice is the top-level key in all configuration below. - You are currently in the same directory where you created your project during the Getting Started guide. @@ -57,19 +57,22 @@ download a zip archive from WordPress.org, or use `curl` to download a tarball: 5. Create a `wp-config.php` file inside the directory from step 4 and copy and paste the contents from [this example file](https://github.com/upsun/snippets/blob/main/examples/wordpress-vanilla/wordpress/wp-config.php). -6. Optional: if you plan on using [wp-cli](https://wp-cli.org/), add a `wp-cli.yml` file and add the following contents +6. To make using [wp-cli](https://wp-cli.org/) easier, add a `wp-cli.yml` file and add the following contents to it: ```yaml path: /app/wordpress/ color: true ``` - - **Note**: If you changed the name of the directory at step 4 you'll need to update the `path` property above to match. + {{< note theme="info" >}} +If you changed the name of the directory at step 4 you'll need to update the `path` property above to match. + {{< /note >}} 7. Add all the files from the steps above to your repository - 1. `git add .` - 2. `git commit -m "adds wordpress core files"` + ```bash location="Terminal" + git add . + git commit -m "adds wordpress core files" + ``` ## 2. Update configuration files @@ -131,6 +134,12 @@ If you changed the name of the directory at step 1.4 you'll need to update the ` source_path: "uploads" ``` + {{< note theme="info">}} +It is possible the `mounts` section is commented out. When uncommenting, pay attention to the indentation and that +the `dependencies` key aligns with other sibling keys (e.g. `relationships`, `web`, etc.) + {{< /note >}} + + 4. Once the images for our application have been built, there are a few key tasks that must be completed before our newly-built application can receive requests. These tasks include: @@ -180,26 +189,36 @@ If you changed the name of the directory at step 1.4 you'll need to update the ` - '/^wp-*/' ``` -6. Optional: Add the wp-cli tool to your application build. Locate the `dependencies:` section that is commented out, - and update it as follows: +6. To ensure we are able to perform tasks later in the deployment stage (e.g. updating the database, flushing cache, etc.) + we need to make sure the [wp-cli](https://wp-cli.org/) utility is a dependency of the application container. While still + in the `.upsun/config.yaml` file, locate the `dependencies.php` section, and add the following: - ```yaml {configFile="app"} - applications: - myapp: - source: - root: "/" - type: 'php:8.3' - - dependencies: - php: - wp-cli/wp-cli-bundle: "^2.4" + ```yaml {configFile="app"} + applications: + myapp: + source: + root: "/" + type: 'php:8.3' + + dependencies: + php: + composer/composer: "^2" + wp-cli/wp-cli-bundle: "^2.4" ``` + {{< note theme="info" >}} + +It is possible the `dependencies` section is commented out. When uncommenting, pay attention to the indentation and that +the `dependencies` key aligns with other sibling keys (e.g. `build`, `hooks`, etc.) + + {{< /note >}} + + 7. Add and commit your changes. ```bash {location="Terminal"} git add .upsun/config.yaml - git commit -m "Updates configuration file" + git commit -m "Updates {{% vendor/name %}} configuration file" ``` ## 3. Update `.environment` @@ -218,13 +237,33 @@ export DB_PASSWORD="$MARIADB_PASSWORD" export DB_SCHEME="$MARIADB_SCHEME" export DATABASE_URL="${DB_SCHEME}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_PATH}" ``` -To configure the remaining environment variables WordPress needs to run smoothly, follow these steps. -1. Open the `.environment` file for editing -2. Add the following at the end of the file: +To configure the remaining environment variables WordPress needs to run smoothly, open the `.environment` file. Just +after the other database-related variables, add a blank line or two and add the following: + +```bash {location=".environment"} +# Routes, URLS, and primary domain +export SITE_ROUTES=$(echo $PLATFORM_ROUTES | base64 --decode) +export UPSTREAM_URLS=$(echo $SITE_ROUTES | jq -r --arg app "${PLATFORM_APPLICATION_NAME}" 'map_values(select(.type == "upstream" and .upstream == $app )) | keys') +export DOMAIN_CURRENT_SITE=$(echo $SITE_ROUTES | jq -r --arg app "${PLATFORM_APPLICATION_NAME}" 'map_values(select(.primary == true and .type == "upstream" and .upstream == $app )) | keys | .[0] | if (.[-1:] == "/") then (.[0:-1]) else . end') +``` + +Save, add, and commit those changes: +```bash {location="Terminal"} +git add .environment +git commit -m "adds remaining environment variables to .environment" +``` + +## 4. Push and deploy +Now that we've added the required files, you're ready to push your changes and deploy your WordPress site: +```bash {location="Terminal"} + +{{% vendor/cli %}} push -y + +``` + +## 5. Optional: ```bash {location=".environment"} - export WP_HOME=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r 'to_entries[] | select(.value.primary == true) | .key') - export WP_SITEURL="${WP_HOME}wordpress" export WP_DEBUG_LOG=/var/log/app.log if [ "$PLATFORM_ENVIRONMENT_TYPE" != "production" ] ; then export WP_ENV='development' @@ -232,15 +271,6 @@ To configure the remaining environment variables WordPress needs to run smoothly export WP_ENV='production' fi ``` -3. Add and commit your changes: - 1. `git add .environment` - 2. `git commit -m "adds remaining environment variables to .environment"` - -## 4. Push and deploy -Now that we've added the required files, you're ready to push your changes and deploy your WordPress site: -```bash -upsun push -y -``` ## Further resources - [All files (Upsun configuration, `.environment`, `wp-cli.yml`, `wp-config.php`)](https://github.com/upsun/snippets/tree/main/examples/wordpress-vanilla) ### Documentation From 28548e3edb1b1cfebc412894fbc756f07a69ce9d Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Tue, 20 May 2025 12:12:26 -0500 Subject: [PATCH 14/27] Apply suggestions from code review Co-authored-by: Kemi Elizabeth <97071326+Kemi-Elizabeth@users.noreply.github.com> --- .../src/get-started/stacks/wordpress/multisite.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index 383b928fc6..2b850f2179 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -16,7 +16,7 @@ These resources provide all the core concepts and common commands you need to kn You will need to make a few changes to your {{% vendor/name %}} configuration for WordPress Multisite to successfully deploy and operate. -Please note that these changes must only be made **after completing the [Getting started guide](/get-started/here/_index.md)**. Once the changes are made, you will have a working WordPress site (see **Assumptions** to read the WordPress guides and understand what your working WordPress site will be based on). +Please note that these changes must only be made **after completing the [Getting started guide](/get-started/here/_index.md)**. You should also already have a working WordPress site (see **Assumptions** for the WordPress guides your WordPress site should be based on). {{% guides/requirements name="WordPress" %}} @@ -80,7 +80,7 @@ applications: The domain(s) of your multisite are stored in the database itself. This creates a challenge in a system like Upsun where you often create [preview environments](/glossary.html#preview-environment) dynamically during development. To ensure -the database for your preview environments are updated with the correct domains, we have created a +the database for your preview environments is updated with the correct domains, we have created a [wp-cli package](https://github.com/upsun/wp-ms-dbu) to automate the process of updating the database with the preview environment's unique domain name. @@ -129,7 +129,7 @@ applications: ## 3. wp-config.php Once our multisite has been set up, we need to expose additional pieces of information inside our `wp-config.php` file. -In your wp-config.php file, right above the section: +In your wp-config.php file, right above the section outlined below: ```php {location="wp-config.php"} /** Absolute path to the WordPress directory. */ @@ -202,7 +202,7 @@ to define('MULTISITE', true); ``` -Add and commit the changes, and push to {{% vendor/name %}}: +Add and commit the changes, then push to {{% vendor/name %}}: ```shell {location="Terminal"} git add wp-config.php @@ -210,7 +210,7 @@ git commit -m "set WordPress to run in multisite mode." {{% vendor/cli %}} push -y ``` -Once the site has finished deploying, you can return the Network Admin --> Sites area of wp-admin and begin adding your +Once the site has finished deploying, you can return to the Network Admin --> Sites area of wp-admin and begin adding your sites. Sites sites. + ++++ +title=Bedrock +highlight=yaml ++++ + +applications: + myapp: + + web: + locations: + "/": + + rules: + ^/license\.text$: + allow: false + ^/readme\.html$: + allow: false + '^/(?!wp/)([_0-9a-zA-Z-]+/)?wp-(?[a-z\-]+).php$': + allow: true + scripts: true + passthru: '/wp/wp-$wproot.php' + # Allows directory-based multisites to still access the wp-admin and wp-include locations + '^/(?!wp/)([_0-9a-zA-Z-]+/)?(?wp-(admin|includes).*)': + allow: true + scripts: true + passthru: '/wp/$adminrewrite' + '^/([_0-9a-zA-Z-]+)/wp-content/(?.*)': + allow: true + scripts: false + passthru: '/wp-content/$content' + expires: 1w + +{{< /codetabs >}} + +{{< note theme="info" >}} +If you followed the Bedrock guide and decided to change the default name of the directory where WordPress is installed +(`wp`), then you will need to update both the rules and `passthru` keys accordingly. +{{< /note >}} ## 2. Update the database during the deploy hook @@ -112,7 +159,7 @@ applications: hooks: deploy: | - set -eux + set -eu # we need the main production url PRODURL=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r --arg app "${PLATFORM_APPLICATION_NAME}" '[.[] | select(.primary == true and .type == "upstream" and .upstream == $app )] | first | .production_url') if [ 'production' != "${PLATFORM_ENVIRONMENT_TYPE}" ] && wp site list --format=count --url="${PRODURL}" >/dev/null 2>&1; then @@ -121,26 +168,50 @@ applications: else echo "Database appears to already be updated. Skipping."; fi + # Flushes the object cache wp cache flush + # Runs the WordPress database update procedure wp core update-db ``` -## 3. wp-config.php +## 3. `wp-config.php` / `config/application.php` + +Once our multisite has been set up, we need to expose additional pieces of information inside our `wp-config.php` (or +`./config/application.php` for Bedrock) file. In your wp-config.php/application.php file, right above the section +outlined below: -Once our multisite has been set up, we need to expose additional pieces of information inside our `wp-config.php` file. -In your wp-config.php file, right above the section outlined below: +{{< codetabs >}} -```php {location="wp-config.php"} ++++ +title=wp-config.php (Vanilla, Composer) +highlight=php ++++ /** Absolute path to the WordPress directory. */ if ( ! defined( 'ABSPATH' ) ) { define( 'ABSPATH', dirname( __FILE__ ) . '/' ); } -``` +<---> ++++ +title=config/application.php (Bedrock) +highlight=php ++++ +/** +* Bootstrap WordPress + */ + if (!defined('ABSPATH')) { + define('ABSPATH', $webroot_dir . '/wp/'); + } +{{< /codetabs >}} + add the following: -```php {location="wp-config.php"} +{{< codetabs >}} ++++ +title=wp-config.php (Vanilla, Composer) +highlight=php ++++ /** * Multisite support */ @@ -162,7 +233,28 @@ if( MULTISITE && WP_ALLOW_MULTISITE) { define('COOKIE_DOMAIN',$site_host); } } -``` + +<---> ++++ +title=config/application.php (Bedrock) +highlight=php ++++ +/** +* Multisite support +*/ +define('WP_ALLOW_MULTISITE', true); //enables the Network setup panel in Tools +define('MULTISITE', false); //instructs WordPress to run in multisite mode + +if( MULTISITE && WP_ALLOW_MULTISITE) { + define('SUBDOMAIN_INSTALL', false); // does the instance contain subdirectory sites (false) or subdomain/multiple domain sites (true) + define('DOMAIN_CURRENT_SITE', parse_url(filter_var(getenv('DOMAIN_CURRENT_SITE'),FILTER_VALIDATE_URL),PHP_URL_HOST)); + define('PATH_CURRENT_SITE', '/'); //path to the WordPress site if it isn't the root of the site (e.g. https://foo.com/blog/) + define('SITE_ID_CURRENT_SITE', 1); //main/primary site ID + define('BLOG_ID_CURRENT_SITE', 1); //main/primary/parent blog ID + +} +{{< /codetabs >}} + where `SUBDOMAIN_INSTALL` is set to `true` if your multisite is a sub/multi-domain site, or `false` if you will be setting up a subdirectory-based multisite. Note that `MULTISITE` is currently set to `false`; we will update this once the database has finished being set up for the multisite. @@ -191,14 +283,14 @@ Alternatively, you can access a terminal session in the app container (`{{% vend `wp core multisite-convert` to install the multisite. {{< /note >}} -## 6. Final change to wp-config.php +## 6. Final change to `wp-config.php` / application.php Return to your wp-config.php file and change -```php {location="wp-config.php"} +```php define('MULTISITE', false); ``` to -```php {location="wp-config.php"} +```php define('MULTISITE', true); ``` @@ -214,24 +306,13 @@ Once the site has finished deploying, you can return to the Network Admin --> Si sites. + ## Further resources From 97365ccc4a5b746134a229519716f6024a3d4856 Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Tue, 20 May 2025 17:05:09 -0500 Subject: [PATCH 20/27] moves cron now to post_deploy, adds extra env vars to .environment --- .../upsun/src/get-started/stacks/wordpress/bedrock.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/bedrock.md b/sites/upsun/src/get-started/stacks/wordpress/bedrock.md index ead3691ed1..9b8c411c72 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/bedrock.md +++ b/sites/upsun/src/get-started/stacks/wordpress/bedrock.md @@ -131,7 +131,7 @@ application can receive requests. Such tasks include: - Running any due cron jobs To perform these tasks, we'll utilize the [deploy hook](/learn/overview/build-deploy.md#deploy-steps). Locate the -`deploy:` section (below the `build:` section). Update the `deploy:` section as follows: +`deploy:` section (below the `build:` section). Update the `deploy:` and `post_deploy` sections as follows: ```yaml {configFile="app"} applications: @@ -147,6 +147,7 @@ applications: wp cache flush # Runs the WordPress database update procedure wp core update-db + post_deploy: # Runs all due cron events wp cron event run --due-now ``` @@ -215,7 +216,12 @@ To configure the remaining environment variables that WordPress needs to run smo 2. Add the following at the end of the file: ```bash {location=".environment"} - export WP_HOME=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r 'to_entries[] | select(.value.primary == true) | .key') + # Routes, URLS, and primary domain + export SITE_ROUTES=$(echo $PLATFORM_ROUTES | base64 --decode) + export UPSTREAM_URLS=$(echo $SITE_ROUTES | jq -r --arg app "${PLATFORM_APPLICATION_NAME}" 'map_values(select(.type == "upstream" and .upstream == $app )) | keys') + export DOMAIN_CURRENT_SITE=$(echo $SITE_ROUTES | jq -r --arg app "${PLATFORM_APPLICATION_NAME}" 'map_values(select(.primary == true and .type == "upstream" and .upstream == $app )) | keys | .[0] | if (.[-1:] == "/") then (.[0:-1]) else . end') + + export WP_HOME="${DOMAIN_CURRENT_SITE}" export WP_SITEURL="${WP_HOME}/wp" export WP_DEBUG_LOG=/var/log/app.log # Uncomment this line if you would like development versions of WordPress on non-production environments. From 689dd005f81ae9a763bb126c4a4120bcece325c4 Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Wed, 21 May 2025 10:22:48 -0500 Subject: [PATCH 21/27] adds option ending step for adding cron job to all WordPress guides --- .../get-started/stacks/wordpress/bedrock.md | 27 ++++++++++++++++ .../get-started/stacks/wordpress/composer.md | 28 +++++++++++++++++ .../get-started/stacks/wordpress/vanilla.md | 31 +++++++++++++++++-- 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/bedrock.md b/sites/upsun/src/get-started/stacks/wordpress/bedrock.md index 9b8c411c72..cd027a9a88 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/bedrock.md +++ b/sites/upsun/src/get-started/stacks/wordpress/bedrock.md @@ -245,6 +245,33 @@ You can now commit all the changes made to `.upsun/config.yaml` and `.environmen upsun push -y ``` +## 9. Routinely run WP Cron (optional) +If your site does not receive enough traffic to ensure [WP Cron jobs](https://developer.wordpress.org/plugins/cron/) run +in a timely manner, or your site uses caching heavily such that WP Cron isn't being triggered, you might consider adding +a [cron job](/create-apps/app-reference/single-runtime-image.html#crons) to your project's configuration to have WP CLI +run those scheduled tasks on a routine basis. To do so, locate the `crons:` section that is commented out, and update it +as follows: + +```yaml {configFile="app"} + applications: + myapp: + source: + root: "/" + type: 'php:8.3' + + crons: + wp-cron: + spec: '*/15 * * * *' + commands: + start: wp cron event run --due-now + shutdown_timeout: 600 +``` +The above example will trigger the wp-cli every 15th minute to run WP Cron tasks that are due. Feel free to adjust based +on your individual requirements. + +{{< note theme="info">}} +When uncommenting, pay attention to the indentation and that the `crons` key aligns with other sibling keys (e.g. `hooks`, `dependencies`, etc.) +{{< /note >}} ## Further resources - [All example files (`.environment`, `.upsun/config.yaml`)](https://github.com/upsun/snippets/tree/main/examples/wordpress-bedrock) diff --git a/sites/upsun/src/get-started/stacks/wordpress/composer.md b/sites/upsun/src/get-started/stacks/wordpress/composer.md index 6f1ac1d37a..af21586dcf 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/composer.md +++ b/sites/upsun/src/get-started/stacks/wordpress/composer.md @@ -299,6 +299,34 @@ You can now commit all the changes made to `.upsun/config.yaml` and `.environmen Once {{% vendor/name %}} has completed building and deploying your project, it will provide the list of routes assigned to your project. You can now visit your site and complete the WordPress installation as you normally would. +## 11. Routinely run WP Cron (optional) +If your site does not receive enough traffic to ensure [WP Cron jobs](https://developer.wordpress.org/plugins/cron/) run +in a timely manner, or your site uses caching heavily such that WP Cron isn't being triggered, you might consider adding +a [cron job](/create-apps/app-reference/single-runtime-image.html#crons) to your project's configuration to have WP CLI +run those scheduled tasks on a routine basis. To do so, locate the `crons:` section that is commented out, and update it +as follows: + +```yaml {configFile="app"} + applications: + myapp: + source: + root: "/" + type: 'php:8.3' + + crons: + wp-cron: + spec: '*/15 * * * *' + commands: + start: wp cron event run --due-now + shutdown_timeout: 600 +``` +The above example will trigger the wp-cli every 15th minute to run WP Cron tasks that are due. Feel free to adjust based +on your individual requirements. + +{{< note theme="info">}} +When uncommenting, pay attention to the indentation and that the `crons` key aligns with other sibling keys (e.g. `hooks`, `dependencies`, etc.) +{{< /note >}} + ## Further resources ### Documentation diff --git a/sites/upsun/src/get-started/stacks/wordpress/vanilla.md b/sites/upsun/src/get-started/stacks/wordpress/vanilla.md index 035e811b4b..6fdb9f1e20 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/vanilla.md +++ b/sites/upsun/src/get-started/stacks/wordpress/vanilla.md @@ -135,8 +135,7 @@ If you changed the name of the directory at step 1.4 you'll need to update the ` ``` {{< note theme="info">}} -It is possible the `mounts` section is commented out. When uncommenting, pay attention to the indentation and that -the `dependencies` key aligns with other sibling keys (e.g. `relationships`, `web`, etc.) +When uncommenting, pay attention to the indentation and that the `mounts` key aligns with other sibling keys (e.g. `relationships`, `web`, etc.) {{< /note >}} @@ -264,6 +263,34 @@ Now that we've added the required files, you're ready to push your changes and d ``` +## 5. Routinely run WP Cron (optional) +If your site does not receive enough traffic to ensure [WP Cron jobs](https://developer.wordpress.org/plugins/cron/) run +in a timely manner, or your site uses caching heavily such that WP Cron isn't being triggered, you might consider adding +a [cron job](/create-apps/app-reference/single-runtime-image.html#crons) to your project's configuration to have WP CLI +run those scheduled tasks on a routine basis. To do so, locate the `crons:` section that is commented out, and update it +as follows: + +```yaml {configFile="app"} + applications: + myapp: + source: + root: "/" + type: 'php:8.3' + + crons: + wp-cron: + spec: '*/15 * * * *' + commands: + start: wp cron event run --due-now + shutdown_timeout: 600 +``` +The above example will trigger the wp-cli every 15th minute to run WP Cron tasks that are due. Feel free to adjust based +on your individual requirements. + + {{< note theme="info">}} +When uncommenting, pay attention to the indentation and that the `crons` key aligns with other sibling keys (e.g. `hooks`, `dependencies`, etc.) + {{< /note >}} + ## Further resources - [All files (Upsun configuration, `.environment`, `wp-cli.yml`, `wp-config.php`)](https://github.com/upsun/snippets/tree/main/examples/wordpress-vanilla) ### Documentation From 5748991790dfa896bc37fd72c0e230f336a3591b Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Wed, 21 May 2025 16:32:15 -0500 Subject: [PATCH 22/27] the default rule needs to passthru to /wp/ --- sites/upsun/src/get-started/stacks/wordpress/bedrock.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/bedrock.md b/sites/upsun/src/get-started/stacks/wordpress/bedrock.md index cd027a9a88..34849db53e 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/bedrock.md +++ b/sites/upsun/src/get-started/stacks/wordpress/bedrock.md @@ -47,7 +47,7 @@ applications: "/": root: "web" # The front-controller script to send non-static requests to. - passthru: "/index.php" + passthru: "/wp/index.php" # Wordpress has multiple roots (wp-admin) so the following is required index: - "index.php" From 4d493aa2fd3931b8fac29e0e9cc01132aaf49f35 Mon Sep 17 00:00:00 2001 From: Paul Gilzow Date: Thu, 22 May 2025 14:57:54 -0500 Subject: [PATCH 23/27] adds needed pieces for bedrock when the multisite is multidomain --- .../get-started/stacks/wordpress/multisite.md | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index 18041be854..53253f0cee 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -252,6 +252,31 @@ if( MULTISITE && WP_ALLOW_MULTISITE) { define('SITE_ID_CURRENT_SITE', 1); //main/primary site ID define('BLOG_ID_CURRENT_SITE', 1); //main/primary/parent blog ID + if (SUBDOMAIN_INSTALL && getenv('PLATFORM_RELATIONSHIPS')) { + $site_host = $_SERVER['HTTP_HOST']) ?? ""; + //we're not running locally so we need to make sure $site_host is set to something appropriate + try { + $validURLs = json_decode(getenv('UPSTREAM_URLS'), true, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + $validURLs = []; + error_log($exception->getMessage()); + } + + //if site_host isnt a valid domain we're expecting, then set it to the default domain + if(!in_array($site_host, array_map(static function (string $url) { + return parse_url($url, PHP_URL_HOST); + }, $validURLs), true)) { + $site_host = parse_url(filter_var(getenv('DOMAIN_CURRENT_SITE'),FILTER_VALIDATE_URL),PHP_URL_HOST); + } + /** + * we have a sub/multidomain multisite, and the site currently being requested is not the default domain, so we'll + * need to set COOKIE_DOMAIN to the domain being requested + */ + if ($site_host !== DOMAIN_CURRENT_SITE) { + define('COOKIE_DOMAIN',$site_host); + } + } + } {{< /codetabs >}} @@ -306,11 +331,10 @@ Once the site has finished deploying, you can return to the Network Admin --> Si sites. {{< codetabs >}} +++ From f1d9d43f72fe117c20083d92c7a16ae4f7320176 Mon Sep 17 00:00:00 2001 From: Kemi Elizabeth <97071326+Kemi-Elizabeth@users.noreply.github.com> Date: Fri, 13 Jun 2025 14:41:08 +0100 Subject: [PATCH 27/27] Update sites/upsun/src/get-started/stacks/wordpress/multisite.md --- sites/upsun/src/get-started/stacks/wordpress/multisite.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sites/upsun/src/get-started/stacks/wordpress/multisite.md b/sites/upsun/src/get-started/stacks/wordpress/multisite.md index 8d37a467b0..11a9c23c23 100644 --- a/sites/upsun/src/get-started/stacks/wordpress/multisite.md +++ b/sites/upsun/src/get-started/stacks/wordpress/multisite.md @@ -121,6 +121,7 @@ applications: expires: 1w {{< /codetabs >}} + {{< note theme="info" >}} If you followed the Bedrock guide and decided to change the default name of the directory where WordPress is installed