---
title: HTTP health checks for headless WordPress environments
description: Learn how to set up health checks for your headless WordPress environments
url: https://developers.wpengine.com/docs/headless-platform/additional-guides/environment-health-checks/
image: https://developers.wpengine.com/og/docs/headless-platform/additional-guides/environment-health-checks.png
---

# HTTP health checks for headless WordPress environments

HTTP health check on the Headless Platform is a check that runs at a high frequency at the environment startup - and then periodically while the environment is running to ensure it is operating correctly.

Once set up, during every deployment the platform will wait for the health check to respond with a successful response (HTTP code `>=200` and `<400`) before marking the deployment as successful. Then, if the environment starts failing while it’s already running (health check will start returning HTTP code `>=400`), the platform will restart the environment.

A health check must be configured by the developer to be enabled for each of the environments that they wished to be monitored.

### Behavior during the environment startup

By default (without the HTTP health check enabled) Headless Platform checks if your environment has bound to a port (see more details in our [documentation](https://developers.wpengine.com/docs/headless-platform/getting-started/deploy-from-existing-repo#using-the-correct-port)). Once it has done so successfully, the environment will be marked as healthy and the deployment as successful which means that your environment is ready to serve the traffic.

If the health check is enabled on your environment, it will instead wait for the environment to respond with an `200` response before marking it as healthy.

### Behavior during the environment runtime

By default (without the HTTP health check enabled), if the environment is bound to a port our platform will not treat it as unhealthy if it starts returning HTTP `5xx` responses.

However once the health check is configured, the environment will be restarted if it starts returning HTTP `5xx` responses.

## Steps

### 1. Add a health check endpoint

Add an endpoint to your environment which returns an HTTP `200` response. For example, add the following under the `/api/healthz.js` file

```javascript
export default function handler(req, res) {
  res.status(200).json({ status: 'ok' });
}
```

> **Tip**
>
> - At startup, the endpoint will get a large volume of requests until it starts returning an HTTP `200` response. This means you *should not* include load sensitive components as part of this health check, such as the WordPress backend.
> - This health check should only test the headless frontend. If it includes the backend and WordPress becomes unhealthy, the frontend could be restarted unnecessarily.
> - The file path itself does not matter and can be set to any value.

### 2. Enable using environment variables

The following environment variables must be added to the headless environment via the User Portal. The path must be the same as the path of the endpoint set up above.

```
HTTP_HEALTH_CHECK_ENABLED=true
HTTP_HEALTH_CHECK_PATH=/api/healthz
```

> **Note**
>
> Modifying environment variables does not trigger a new deployment automatically - a new deployment is needed for the health check to be applied.

### 3. See it working

Once the environment is deployed successfully, the new health check will be working.

> **Warning**
>
> - Health check logs do not show up in headless access logs.
> - You can add logging to the health check endpoint, but this is not advised due to the high request volume and regular checks.

## Verify the outcome

Trigger a deployment, then confirm the deployment is marked successful only after your health check path returns an HTTP `2xx` response.

## Was this helpful?

Thanks for the feedback!

```json
{"@context":"https://schema.org","@graph":[{"@type":"WebSite","@id":"https://developers.wpengine.com/#website","name":"WP Engine Product Documentation","url":"https://developers.wpengine.com/","description":"Resources for developing, deploying, and scaling on WP Engine.","inLanguage":"en-US","keywords":["API documentation","product documentation","headless WordPress","managed WordPress hosting"],"publisher":{"@id":"https://wpengine.com/#organization"}}]}
```
