Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGS-7678] WP config HTTP_HOST documentation updates #8969

Merged
merged 19 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions source/content/guides/multisite/03-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,19 @@ Make sure [Terminus](/terminus) is installed and [authenticated](/terminus/insta

1. Open the `code` folder in your SFTP client, and download your site's `wp-config.php` file.

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:

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.
```php:title=wp-config.php
define( 'WP_ALLOW_MULTISITE', true );
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomains
$base = '/';
define( 'DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST'] );
define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomain installs.
define( 'DOMAIN_CURRENT_SITE', PANTHEON_HOSTNAME );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
```

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.
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.

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

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

```php:title=wp-config.php
define( 'WP_ALLOW_MULTISITE', true );
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomains
define( 'DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST'] );
define( 'DOMAIN_CURRENT_SITE', PANTHEON_HOSTNAME );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
Expand Down Expand Up @@ -164,6 +164,16 @@ After these steps are complete, both sites on the WordPress Multisite should loa

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.

## Troubleshooting

### "Undefined index: HTTP_HOST" PHP Warnings

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.

```php
define( 'DOMAIN_CURRENT_SITE', PANTHEON_HOSTNAME );
```

## More Resources

- [Environment-Specific Configuration for WordPress Sites](/guides/environment-configuration/environment-specific-config)
Expand Down
12 changes: 11 additions & 1 deletion source/content/guides/php/04-wp-config-php.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ audience: [development]
product: [--]
integration: [--]
tags: [wp-config]
contributors: [masonjames]
contributors: [masonjames, jazzsequence]
showtoc: true
permalink: docs/guides/php/wp-config-php
---
Expand Down Expand Up @@ -107,6 +107,16 @@ The following example shows how to hard-code your WordPress debug configuration

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

### How can I override the default `PANTHEON_HOSTNAME` value?

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:

```php:title=wp-config.php
define( 'PANTHEON_HOSTNAME', 'example.com' );
```

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.

### How can I read the Pantheon environment configuration, like database credentials?

Refer to [Reading the Pantheon Environment Configuration](/guides/environment-configuration/read-environment-config).
Expand Down
14 changes: 14 additions & 0 deletions source/content/wordpress-known-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ Pantheon supports designated use cases for [WordPress Multisite](/guides/multisi

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.

## `Undefined array key "HTTP_HOST"` PHP warnings

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:

```php
if (isset($_SERVER['HTTP_HOST'])) {
// Your code here
}
```

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.

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.

## Plugins with Known Issues
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.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: WordPress and Pantheon MU Plugin v1.4.1 update
published_date: "2024-04-2x"
categories: [wordpress, plugins, action-required]
---

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).

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.
Loading