Overview
This guide provides instructions for deploying and working with Twill, an “open-source CMS toolkit for Laravel” on Upsun, by Platform.sh. If you’re not familiar with Forem, it’s a Laravel package that helps developers rapidly create a custom CMS that is beautiful, powerful, and flexible. Before we dive in, let’s establish some assumptions that we’ve made about you to ensure you can follow this guide successfully:- You have an account set up on Upsun.com and the necessary permissions to create a new project
- You have the Upsun CLI installed
- You have authenticated in the CLI
- You have the same PHP version installed locally that you want to use in your application container, and it has both pdo and pdo_mysql extensions enabled.
Setting up the application and repository
First, we need to start a Laravel project. From a terminal/command prompt, create a new Laravel project locally:cd into the new directory.
Once the project is created and we’re in the new directory, we’ll go go ahead and initialize our git repository.
From your terminal/command prompt:
master. I’m going to rename mine to main and will reference this name
throughout the remainder of this guide. To rename the branch, from your terminal/command prompt:
.environmentin the root of the Forem repository and a new directory.upsunwith a single file inside namedconfig.yaml
git add and git commit.
Leverage environment variables
While theproject:init command correctly identified our project as being Laravel-based, and correctly set up our
Upsun configuration files for success, there are a few changes we’ll need to make in order to deploy Twill.
Upsun does not read environment variable values from .env but does provide a way to generate environment variables
via script. The .environment file that the CLI generated previously runs as a script in dash when the container starts
and on all SSH logins. It can be used to set any environment variables directly, such as the PATH variable. Perfect!
Note: I’m going to walk through each group of additions to this file, but a link to the file in its entirety will also be included at the end of this post.
APP_KEY and value that Laravel generated for us in the .env file into our
.environment. With your favorite IDE, open up the .env file and copy the line that starts with APP_KEY. Next, open
the .environment file. Scroll down to the bottom, just past export REDIS_URL. On a new line, type export and
paste in the line we just copied. It should look similar to the following:
.environment file again and at the top of the file, add the following:
DB_. They should be located right between the comments:
# Set database environment variables and # Set Laravel-specific environment variables.
Once you’ve found those variables, replace them with the following:
Create the Upsun project
Before we can deploy our application, we’ll need to create a new project on Upsun. To do so, we’ll type the command below into command line:- Your organization
- The project’s title
- The region you want the application housed
- The branch name (use the same one you set earlier) For now, allow the CLI tool to set Upsun as your repository’s remote, and then select Y for the tool to create the project. The Upsun bot will begin the generation of your Upsun project and once done, will report back the details of your project including the project’s ID, and URL where you can manage the project from the Upsun web console. Don’t worry if you forget any of this information, you can retrieve it later with:
First push
We’re finally to the point where we can push our repository to Upsun and have it perform the first build:Finish setting up Twill
While we added Twill as a dependency earlier, we still haven’t installed it. To do so, we still need to run thetwill:install Artisan command. This will:
- Create an
admin.phproutes file in our application’s routes directory. This is where we will declare our own admin console routes. - Migrate the database with Twill’s migrations.
- Publish Twill’s configuration files to our application’s config directory.
- Publish Twill’s assets for the admin console UI.
- Prompt us to create a superadmin user.
PLATFORM_RELATIONSHIPS environment variable:
.environment file to create the
environment variables in our current terminal session that Twill can utilize:
- config/translatable.php
- config/twill.php
- public/.gitkeep
- public/assets/*
- resources/views/site/*
- routes/twill.php
git add all the above and git commit, you’re ready to push.