> ## Documentation Index
> Fetch the complete documentation index at: https://docs.preprod.world/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate a CDN resource with Perch

Perch can deliver uploaded resources through a Gcore CDN resource by adding the CDN domain to its resource paths.

<Warning>
  Back up site files and the database before making changes. These steps assume a standard local `perch/resources` directory without a custom or remote resource-storage handler.
</Warning>

Create a [CDN resource](/cdn/getting-started/create-a-cdn-resource/create-a-cdn-resource) before starting the integration. Configure its [custom domain](/cdn/cdn-resource-options/general/create-and-set-a-custom-domain-for-the-content-delivery-via-cdn) with a valid CNAME record and an active SSL certificate.

1. In the [Gcore Customer Portal](https://portal.gcore.com), find the custom domain on the [CDN resources](https://portal.gcore.com/cdn/resources/list) page.

2. Confirm that the CDN origin can retrieve a known file from the default resource directory. Perch requires this directory to be directly accessible through a URL, as described in the [resource documentation](https://docs.grabaperch.com/perch/resources/).

   Use the origin protocol and hostname configured for the CDN resource:

   ```text theme={null}
   https://origin.example.com/perch/resources/example.jpg
   ```

   Continue only after the origin URL returns the expected file.

3. Open `perch/config/config.php` on the server and find:

   ```php theme={null}
   define('PERCH_RESPATH', PERCH_LOGINPATH . '/resources');
   ```

4. Replace it with the custom domain as the host prefix:

   ```php theme={null}
   define('PERCH_RESPATH', 'https://cdn.site.com' . PERCH_LOGINPATH . '/resources');
   ```

5. Optional — Perch [resource buckets](https://docs.grabaperch.com/perch/resources/buckets/) can use local directories, remote storage, private download scripts, or custom handlers. In `perch/config/buckets.php`, update only local file buckets that the same CDN origin can access, and leave remote or access-controlled buckets unchanged.

   Prefix the eligible bucket's `web_path` with the custom domain while keeping its original path:

   ```php theme={null}
   // Before
   'web_path' => '/my/bucket/path',

   // After
   'web_path' => 'https://cdn.site.com/my/bucket/path',
   ```

6. Save the configuration files.

7. Confirm the integration by opening the browser's developer tools (press <kbd>F12</kbd>), selecting the **Network** tab, and refreshing the page — eligible resource URLs should now load from the custom domain instead of the origin domain.
