Upsun User Documentation

Laravel Bridge

Upsun Beta access

Test and provide feedback for our newest offering - Upsun!

You can register for the Beta by clicking here and completing the form.

Sign up for Beta access

Connect your Laravel-based app to Upsun with the platformsh/laravel-bridge library.

Laravel expects all configuration to come in through environment variables with specific names in a specific format. Upsun provides configuration information as environment variables in a different specific format. This library handles mapping the Upsun variables to the format Laravel expects for common values.

Usage Anchor to this heading

To retrieve the library, use Composer:

composer require platformsh/laravel-bridge

What is mapped Anchor to this heading

  • If a Upsun relationship named database is defined, it is taken as an SQL database and mapped to the DB_* environment variables for Laravel.

  • If a Upsun relationship named rediscache is defined, it is mapped to the REDIS_* environment variables for Laravel. The CACHE_DRIVER variable is also set to redis to activate it automatically.

  • If a Upsun relationship named redissession is defined, the SESSION_DRIVER is set to redis and the REDIS_* variables set based on that relationship. NOTE: This means you must set 2 relationships to the same Redis service and endpoint, as Laravel reuses the same backend connection.

  • The Laravel APP_KEY is set based on the PLATFORM_PROJECT_ENTROPY variable, which is provided for exactly this purpose.

  • The Laravel APP_URL variable is set based on the current route, when possible.

  • The SESSION_SECURE_COOKIE variable is set to true if it’s not already defined. A Upsun environment is by default encrypted-always, so there’s no reason to allow unencrypted cookies. Overwrite this by setting the Upsun variable env:SESSION_SECURE_COOKIE to 0.

  • The MAIL_DRIVER, MAIL_HOST, and MAIL_PORT variables are set to support sending email through the Upsun mail gateway. The MAIL_ENCRYPTION value is also set to 0 to disable TLS, as it isn’t needed or supported within Upsun’s network. Note that doing so is only supported on Laravel 6.0.4 and later. On earlier versions, you must manually modify mail.php and set encryption to null:

        'encryption' => null,

Common environment variables not set Anchor to this heading

Laravel provides reasonable defaults for many environment variables already and this library doesn’t override those. Customize them by setting a Upsun environment variable named env:ENV_NAME. (Note the env: prefix.)

Learn more about defining and using environment variables for your Upsun projects.

The variables you are most likely to want to override are:

  • env:APP_NAME: The human-friendly name of the app.
  • env:APP_ENV: Whether the app is in production or development mode.
  • env:APP_DEBUG: Set true to enable verbose error messages.

Note the PLATFORM_ENVIRONMENT_TYPE variable is automatically generated and contains the type of your environment.

Now that your Laravel app is connected to Upsun, deploy it to see it in action.

Is this page helpful?