## POST /api/v2/shared-hosting/{accountId}/php

**Set a website's PHP version**

Give one website its own PHP version. Send `inherit` to make it follow the account's version again. The setting is written as a marked Hostup block at the end of the website's `.htaccess`. It applies from the next request. An older per-domain setting on the server is removed first. Domains served from the same folder share the setting. So do websites in sub-folders without a setting of their own. Take `version` from `installedVersions` on [`GET /api/v2/shared-hosting/{accountId}/php`](/endpoints/webhosting-services/get-v2-shared-hosting-accountid-php/). A website that runs PHP-FPM returns 409 `domain_not_eligible`. The account must be active and on cPanel.

### Related Endpoints

- `GET /api/v2/shared-hosting/{accountId}/php`: Get PHP versions per website
- `GET /api/v2/shared-hosting/{accountId}`: Get a web hosting account
- `PATCH /api/v2/shared-hosting/{accountId}`: Rename a web hosting account

### Headers

- `Authorization`: Bearer $HOSTUP_API_KEY
- Scopes: `write:hosting`, `console:services`
- `Content-Type`: application/json

### Parameters

- `accountId` (path, string, required): The web hosting account ID (`acct_…`). Example: `acct_01hxa3b4c5d6e7f8g9h0j1k2m3`

### Request Body

- `domain` (string, required): The website's domain on the account. Example: `example.com`
- `version` (string, required): `inherit` or an installed version such as `alt-php82`. Example: `alt-php82`

### Request Examples

#### Run PHP 8.2

```bash
curl -X POST "https://cloud.hostup.se/api/v2/shared-hosting/acct_01hxa3b4c5d6e7f8g9h0j1k2m3/php" \
  -H "Authorization: Bearer $HOSTUP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "domain": "example.com",
    "version": "alt-php82"
  }'
```

```json
{
  "domain": "example.com",
  "version": "alt-php82"
}
```

#### Follow the account's version

```bash
curl -X POST "https://cloud.hostup.se/api/v2/shared-hosting/acct_01hxa3b4c5d6e7f8g9h0j1k2m3/php" \
  -H "Authorization: Bearer $HOSTUP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "domain": "example.com",
    "version": "inherit"
  }'
```

```json
{
  "domain": "example.com",
  "version": "inherit"
}
```

### Response Schema

- `domain` (string, required): The website's domain, in punycode form. Example: `example.com`
- `version` (string, required): The setting that was saved. Example: `alt-php82`

### Responses

#### 200 - The setting was saved and read back.
```json
{
  "domain": "example.com",
  "version": "alt-php82"
}
```

#### 400 - `invalid_request`: the body is invalid. With the pointer `/body/version`, that version is not installed.

#### 401 - Unauthorized. Authentication is required.
```json
{
  "type": "https://developer.hostup.se/errors/unauthorized",
  "title": "Unauthorized",
  "status": 401,
  "detail": "Authentication is required.",
  "code": "unauthorized",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 403 - Forbidden. The caller lacks a required scope or does not own the resource.
```json
{
  "type": "https://developer.hostup.se/errors/forbidden",
  "title": "Forbidden",
  "status": 403,
  "detail": "The caller lacks a required scope or does not own the resource.",
  "code": "forbidden",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 404 - The domain is not a website on this account (`domain_not_found`).

#### 409 - `domain_not_eligible`: the website runs PHP-FPM. `account_not_eligible_cpanel`: the account is not on cPanel.
```json
{
  "type": "https://developer.hostup.se/errors/invalid_request",
  "title": "Validation failed",
  "status": 400,
  "detail": "The request body failed validation.",
  "code": "invalid_request",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z",
  "errors": [
    {
      "pointer": "/name",
      "detail": "`name` is required.",
      "code": "invalid_request"
    }
  ]
}
```

#### 429 - Rate limited. Retry after the limit resets. 429 responses include `Retry-After` seconds plus `X-RateLimit-*` headers.
```json
{
  "type": "https://developer.hostup.se/errors/rate_limit_exceeded",
  "title": "Too many requests",
  "status": 429,
  "detail": "Rate limit exceeded. Please try again later.",
  "code": "rate_limit_exceeded",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 500 - Internal error. Retry later or contact support if the issue persists.
```json
{
  "type": "https://developer.hostup.se/errors/internal_error",
  "title": "Internal server error",
  "status": 500,
  "detail": "An unexpected error occurred. Retry later or contact support if the issue persists.",
  "code": "internal_error",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 502 - The setting could not be saved or confirmed (`upstream_failed`). Read the state with GET before you retry.
