Skip to content

craftcms/cloud-extension-yii2

Repository files navigation

Craft Cloud icon

Craft Cloud Extension

Welcome to Craft Cloud!

This repository contains source code for the craftcms/cloud Composer package, which is required to run a Craft project on our first-party hosting platform, Craft Cloud.

When installed, the extension automatically bootstraps itself and makes necessary application configuration changes for the detected environment:

  • 🌩️ Cloud: There’s no infrastructure settings to worry about—database, queue, cache, and session configuration is handled for you.
  • 💻 Local development: Craft runs normally, in your favorite development environment.

✨ To learn more about Cloud, check out our website—or dive right in with Craft Console. Interested in everything the extension does to get your app ready for Cloud? Read our Cloud extension deep-dive, in the knowledge base.

Installation

The Cloud extension can be installed in any existing Craft 4.6+ project by running php craft setup/cloud. Craft will add the craftcms/cloud package and run the extension’s own setup wizard.

Tip

This process includes the creation of a craft-cloud.yaml configuration file which helps Cloud understand your project’s structure and determines which versions of PHP and Node your project will use during builds and at runtime.

When you deploy a project to Cloud, the cloud/up command will run, wrapping Craft’s built-in up command and adding the cache and session tables (if they’re not already present).

Filesystem

When setting up your project’s assets, use the provided Craft Cloud filesystem type. Read more about managing assets in Cloud projects.

Developer Features

Template Helpers

cloud.artifactUrl()

Generates a URL to a resource that was uploaded to the CDN during the build and deployment process.

{# Output a script tag with a build-specific URL: #}
<script src="{{ cloud.artifactUrl('dist/js/app.js') }}"></script>

{# You can also use the extension-provided alias: #}
{% js '@artifactBaseUrl/dist/js/app.js' %}

Read more about how to use artifact URLs.

cloud.isCraftCloud

true when the app detects it is running on Cloud infrastructure, false otherwise.

{% if cloud.isCraftCloud %}
  Welcome to Cloud!
{% endif %}

Aliases

The following aliases are available, in addition to those provided by Craft.

@web

On Cloud, the @web alias is guaranteed to be the correct environment URL for each HTTP context, whether that be a preview domain or custom domain.

@artifactBaseUrl

Equivalent to cloud.artifactUrl(), this allows Project Config settings to take advantage of dynamic, build-specific CDN URLs.

Configuration

Most configuration (to Craft and the extension itself) is handled directly by Cloud infrastructure, through environment overrides. These options are provided strictly for reference, and have limited utility outside the platform.

Option Type Description
artifactBaseUrl `string null`
s3ClientOptions array Additional settings to pass to the Aws\S3\S3Client instance when accessing storage APIs.
cdnBaseUrl string Used when building URLs to assets and other build artifacts.
sqsUrl string Determines how Craft communicates with the underlying queue provider.
projectId string UUID of the current project.
environmentId string UUID of the current environment.
buildId string UUID of the current build.
accessKey string AWS access key, used for communicating with storage APIs.
accessSecret string AWS access secret, used in conjunction with the accessKey.
accessToken string AWS access token.
redisUrl string Connection string for the environment’s Redis instance.
signingKey string A secret value used to protect transform URLs against abuse.
useAssetBundleCdn boolean Whether or not to enable the CDN for asset bundles.
previewDomain `string null`
useQueue boolean Whether or not to use Cloud’s SQS-backed queue driver.
region string The app region, chosen when creating the project.
useAssetCdn boolean Whether or not to enable the CDN for uploaded assets.
useArtifactCdn boolean Whether or not to enable the CDN for build artifacts and asset bundles.

These options can also be set via environment overrides beginning with CRAFT_CLOUD_.