Skip to content

Commit 1c2e745

Browse files
authored
[BUGS-7678] WP config HTTP_HOST documentation updates (#8969)
* update recommended config for HTTP_HOST issue this matches what we're putting into the mu-plugin * add undefined array key HTTP_HOST warning as a known issue * add release note for mu-plugin update * reset the SUBDOMAIN_INSTALL constant back to what it was before * update the docs about $_SERVER being/not being available whether or not the full superglobal is available is somewhat irrelevant, we can just talk about the value we actually care about, which is HTTP_HOST * clarify language about web/non-web requests * update docs to remove complicated switch * also update the complicated switch logic for the gui instructions * add HTTP_HOST warning info to troublehsooting at the bottom * detail how to override PANTHEON_HOSTNAME * re-add WP_ALLOW_MULTISITE to code blocks was pulled in the purge * clarify the language a bit * remove unnecessary extra line and make `wp-config.php` a code block * update troubleshooting info for HTTP_HOST warnings * whitespace * update release note * add contrib * update the date * update code snippet to include fallback to `HTTP_HOST` if `$_ENV['PANTHEON_ENVIRONMENT']` is unset (e.g. in non-Lando local development environments), using PANTHEON_HOSTNAME will fatal as undefined, so we still need a fallback here.
1 parent bb9fb95 commit 1c2e745

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

Diff for: source/content/guides/multisite/03-config.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ Make sure [Terminus](/terminus) is installed and [authenticated](/terminus/insta
6868
6969
1. Open the `code` folder in your SFTP client, and download your site's `wp-config.php` file.
7070
71-
1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` from a hardcoded URL to a dynamic URL `$_SERVER['HTTP_HOST']`. This automatically detects the URL in each environment. You must replace this variable. For example:
72-
71+
1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` to a hardcoded URL. We have provided a constant in `wp-config-pantheon.php`, `PANTHEON_HOSTNAME` that defaults to a dynamic URL for web requests (`$_SERVER['HTTP_HOST']`, when available), while providing a fallback for non-web requests (notably workflows like search and replace) that do not have a `$_SERVER['HTTP_HOST']` value.
72+
7373
```php:title=wp-config.php
7474
define( 'WP_ALLOW_MULTISITE', true );
7575
define( 'MULTISITE', true );
76-
define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomains
77-
$base = '/';
78-
define( 'DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST'] );
76+
define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomain installs.
77+
// Use PANTHEON_HOSTNAME if in a Pantheon environment, otherwise use HTTP_HOST.
78+
define( 'DOMAIN_CURRENT_SITE', defined( 'PANTHEON_HOSTNAME' ) ? PANTHEON_HOSTNAME : $_SERVER['HTTP_HOST'] );
7979
define( 'PATH_CURRENT_SITE', '/' );
8080
define( 'SITE_ID_CURRENT_SITE', 1 );
8181
define( 'BLOG_ID_CURRENT_SITE', 1 );
8282
```
8383

84-
Refer to the [wp-config-php documentation](/guides/php/wp-config-php#write-logic-based-on-the-pantheon-server-environment) if you have an environment specific configuration.
84+
Refer to the [`wp-config.php` documentation](/guides/php/wp-config-php#write-logic-based-on-the-pantheon-server-environment) if you have an environment specific configuration.
8585

8686
1. Save your changes and upload the `wp-config.php` file to Pantheon's **Dev** environment.
8787

@@ -120,9 +120,11 @@ Complete the steps below after spinning up a new WPMS site from the correct Cust
120120
1. Locate the `/* That's all, stop editing! Happy Pressing. */` line, and add the following code above this line to enable the WPMS configuration.
121121

122122
```php:title=wp-config.php
123+
define( 'WP_ALLOW_MULTISITE', true );
123124
define( 'MULTISITE', true );
124125
define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomains
125-
define( 'DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST'] );
126+
// Use PANTHEON_HOSTNAME if in a Pantheon environment, otherwise use HTTP_HOST.
127+
define( 'DOMAIN_CURRENT_SITE', defined( 'PANTHEON_HOSTNAME' ) ? PANTHEON_HOSTNAME : $_SERVER['HTTP_HOST'] );
126128
define( 'PATH_CURRENT_SITE', '/' );
127129
define( 'SITE_ID_CURRENT_SITE', 1 );
128130
define( 'BLOG_ID_CURRENT_SITE', 1 );
@@ -164,6 +166,16 @@ After these steps are complete, both sites on the WordPress Multisite should loa
164166
165167
Explore the WordPress Network Dashboard to become familiar with the variety of additional settings. You can review the options that are available for each site you create, manage users across WordPress Multisite, and learn about the network settings. After you explore the WordPress Network Dashboard, learn how to use the WordPress Multisite with the Pantheon Workflow.
166168
169+
## Troubleshooting
170+
171+
### "Undefined index: HTTP_HOST" PHP Warnings
172+
173+
If you see notices in your PHP logs similar to `PHP Warning: Undefined index: HTTP_HOST`, this is likely because there is some code in your configuration that is using `$_SERVER['HTTP_HOST']` without checking if it is set. This is a common issue with WP-CLI, as it does not have the same environment variables set as a web request. Instead of relying on `$_SERVER['HTTP_HOST']`, you can use the `PANTHEON_HOSTNAME` constant, which is set by Pantheon in `wp-config-pantheon.php` and is available in all environments.
174+
175+
```php
176+
define( 'DOMAIN_CURRENT_SITE', PANTHEON_HOSTNAME );
177+
```
178+
167179
## More Resources
168180
169181
- [Environment-Specific Configuration for WordPress Sites](/guides/environment-configuration/environment-specific-config)

Diff for: source/content/guides/php/04-wp-config-php.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ audience: [development]
1010
product: [--]
1111
integration: [--]
1212
tags: [wp-config]
13-
contributors: [masonjames]
13+
contributors: [masonjames, jazzsequence]
1414
showtoc: true
1515
permalink: docs/guides/php/wp-config-php
1616
---
@@ -107,6 +107,16 @@ The following example shows how to hard-code your WordPress debug configuration
107107

108108
<Partial file="wp-debugging.md" />
109109

110+
### How can I override the default `PANTHEON_HOSTNAME` value?
111+
112+
In your `wp-config.php`, above the line that requires `wp-config-pantheon.php`, you can set the `PANTHEON_HOSTNAME` constant to the desired value:
113+
114+
```php:title=wp-config.php
115+
define( 'PANTHEON_HOSTNAME', 'example.com' );
116+
```
117+
118+
Note that in most cases you shouldn't need to do this. The logic in the [`wp-config-pantheon.php`](https://github.com/pantheon-systems/WordPress/blob/default/wp-config-pantheon.php#L98) covers most instances where you might need a unique hostname. It's recommended that you only change this in very specific cases and your code has conditions to handle those.
119+
110120
### How can I read the Pantheon environment configuration, like database credentials?
111121

112122
Refer to [Reading the Pantheon Environment Configuration](/guides/environment-configuration/read-environment-config).

Diff for: source/content/wordpress-known-issues.md

+14
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ Pantheon supports designated use cases for [WordPress Multisite](/guides/multisi
5151

5252
It's especially ill-advised to use Multisite to set up many distinct/separate sites — e.g. running different plugins, for different customers — on a single code installation.
5353

54+
## `Undefined array key "HTTP_HOST"` PHP warnings
55+
56+
If you are seeing an error like `PHP Warning: Undefined array key "HTTP_HOST"` pointing to a WP-CLI file, this is likely because there is some code in your configuration that is using `$_SERVER['HTTP_HOST']` without checking if it is set. This is a common issue with WP-CLI, as it does not have the same environment variables set as a web request. You can resolve this by checking if the key is set before using it:
57+
58+
```php
59+
if (isset($_SERVER['HTTP_HOST'])) {
60+
// Your code here
61+
}
62+
```
63+
64+
The simplest solution is to search your codebase for `$_SERVER['HTTP_HOST']` and add a check for `isset()` before using it. It's generally a good idea to set a fallback value if the key is not set, to prevent unexpected behavior.
65+
66+
If you are seeing this in a WordPress multisite environment, it might be because your `DOMAIN_CURRENT_SITE` value is set to `$_SERVER['HTTP_HOST']` in your `wp-config.php`. You can set this to the `PANTHEON_HOSTNAME` constant provided by Pantheon instead. See the [WordPress Multisite documentation](/guides/multisite/config) for more information.
67+
5468
## Plugins with Known Issues
5569
See [WordPress Plugins and Themes with Known Issues](/plugins-known-issues) for a list of WordPress plugins that are not supported and/or require workarounds.
5670

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: WordPress and Pantheon MU Plugin v1.4.1 update
3+
published_date: "2024-04-30"
4+
categories: [wordpress, plugins, action-required]
5+
---
6+
7+
We have updated the WordPress core upstreams (WordPress and WordPress (Composer Managed)) to provide a new `PANTHEON_HOSTNAME` constant. This value can be helpful when defining `DOMAIN_CURRENT_SITE` on WordPress multisite installations. By default, the `PANTHEON_HOSTNAME` constant is set to the value of the `HTTP_HOST` server variable, which is the hostname of the request. However, when this value is unavailable, the `PANTHEON_HOSTNAME` provides fallback values, thereby avoiding "Undefined index: HTTP_HOST" warnings. For more information, refer to our [WordPress Multisite configuration guide](/guides/multisite/config).
8+
9+
The latest [1.4.1 release](https://github.com/pantheon-systems/pantheon-mu-plugin/releases) of the Pantheon MU Plugin updates the recommended configuration for WordPress multisite to use the new `PANTHEON_HOSTNAME` constant when defining `DOMAIN_CURRENT_SITE` rather than the previous recommendation -- either `$_SERVER['HTTP_HOST']` or a complicated PHP switch.

0 commit comments

Comments
 (0)