How to deploy Drupal on cloud with Docker
Tags: drupal, docker, cloud, devops
Published: 2022-03-21 17:23:07

Drupal is an open source content management platform powering millions of websites and applications.
We will see how you can easily deploy a simple Drupal website on Docker to the cloud with ScaleDynamics.

## Introduction

[Drupal](https://www.drupal.org/) is one of the most popular CMS (Content Management Software).
Build with [PHP](https://www.php.net/), It is a versatile open source platform for building amazing digital experiences.
Drupal is used to make many of the websites and applications you use every day, see the [official showcases](https://www.drupal.com/showcases).

![Drupal logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hqgdgs7cikiswonlwe11.png)

Drupal has great standard features, like easy content authoring, reliable performance, and excellent security.
But what sets it apart is its flexibility; modularity is one of its core principles.

## Prerequisites

To follow this tutorial, we will need:

- Node.js <= 12, we recommend to install the [latest LTS version](https://nodejs.org/en/download/)
- Basic knowledge of [Docker](https://www.docker.com/), and more specifically about [Dockerfile](https://docs.docker.com/engine/reference/builder/)

## Init your Drupal application

From your terminal, start by creating a new folder named `drupal-app` and change directory into it:

```shell
mkdir drupal-app
cd drupal-app
```

Then create a new file named `Dockerfile` and paste the following code into it, in order to build you container from an [official image of Drupal](https://hub.docker.com/_/drupal) downloaded from [Docker Hub](https://hub.docker.com/):

```
# drupal-app/Dockerfile

FROM drupal:latest
EXPOSE 80
```

In this configuration, we have chosen the official Drupal image with the `latest` tag. For a production use case, we recommend setting a stable version with a specified number, like `drupal:9.3` for example.

## Configure your cloud deployment

The application is ready, now let's look at the deployment part.

### Account creation and resource selection

To deploy this application on ScaleDynamics's cloud, you need an account and create an environment with a resource for it. The cloud resource provides virtual CPU and storage capacities used to execute the app. In this tutorial we will use a free shared resource available on ScaleDynamics’s cloud. These are the best one for testing. In this tutorial we will see later how you can upgrade to a dedicated production resource on the public cloud provider and region of your choice.

If you don't have an account, feel free to create one [here](https://console.scaledynamics.com/auth/signup/) (it's free and no credit card are required). Once your account is created, sign in.

Let's create a project and an environment on the ScaleDynamics's [Console](https://scaledynamics.com/console). Select your organization, create a new project, then create a new environment. Now you need to choose what kind of service is required for your deployment. There are four types:

- Managed HTTP Docker
- Managed Node.js server
- Managed Node.js module
- Static assets hosting

For this Drupal project, we need a Docker container to run the PHP server. Let's pick the **managed HTTP Docker**. You can learn more on the other types in the [ScaleDynamics documentation](https://docs.scaledynamics.com/).

![Environment creation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/juhgnbeo3lumwl555708.gif)

### Configuration file

Now let's add a configuration to tell the SDK what type of application we want to deploy.  
At the root of the project, create a new file named `warp.config.js` with the following content:

```js
// drupal-app/warp.config.js

module.exports = {
  docker: "drupal-app",
};
```

## Deploy your Drupal container

Next to deploy your container on the ScaleDynamics platform, you have to use the CLI from SDK.

### Install SDK

First, install once our public SDK called [`warp`](https://www.npmjs.com/package/warp) and available on the official npm registry: https://www.npmjs.com/package/warp

Install the library as development dependency in your project:

```shell
npm init -y
npm install --save-dev warp
```

Or, install it as an npm global dependency on your system:

```shell
npm install -g warp
```

For the next steps, we will use the `npx` command to run each `warp` command.  
The `npx` command allows you to run an arbitrary command from an npm package (either one installed locally, or fetched remotely), in a similar context as running it via `npm run`.

If you need help on the `warp` CLI, just run the help command as below:

```shell
npx warp --help
```

See more about [SDK installation](https://docs.scaledynamics.com/docs/installation) and its use in the ScaleDynamics documentation.

### Login to ScaleDynamics

For the first time, you must login to the ScaleDynamics platform. So run once the `warp login` command to enter your account credentials:

```shell
npx warp login
```

Note that the prompt will ask you to select an organization, only if you have more than one!

### Run deployment

Now it's time to deploy your awesome Drupal project on your managed cloud resource.

To achieve that step, you just need to run the `warp deploy` simple command line:

```shell
npx warp deploy
```

The deploy command will detect that your application needs to be deployed as Docker resource. The interactive mode will ask you to pick a project and an environnement, in order to deploy your Drupal container on cloud. Then you will have to choose a domain name as public URL. Leave blank if you want a generate random one.

![npx deploy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xuk4hnvito5h3u24prbt.png)

Your Drupal container is now deployed and ready to use from the returned public URL! On the next step, you will have to configure your Drupal website.

In addition, you can automate your deployment and avoid interactive mode with the following options. It can be useful to run that operation from your [CI/CD pipeline](https://docs.scaledynamics.com/docs/advanced-usage/cicd) by example.

```shell
npx warp deploy --project <project-name> --env <env-name>
```

See more about `warp deploy` command in the [SDK documentation](https://docs.scaledynamics.com/docs/sdk/cli#deploy)

## Setup your Drupal website

Open your browser, go the URL of your managed Docker resource that now serves your Drupal container and start the setup "set-by-step" of your website.

The first load will show you the Drupal interactive initial setup. First, pick your language on form and continue.

![drupal setup step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0lxv24lmzpobq9ydqmg7.png)

Then select the "**Demo: Umami Food Magazine**" as current installation profile. This option will generate a ready-to-use website sample built from the Drupal CMS that show off some of its most common capabilities. If you are already familiar with the Drupal platform, choose a "Standard" or "Minimal" profile according to your needs.

![drupal setup step 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k0ziglipazpstw4ldb9p.png)

Next step, select the "**SQLite**" database for this sample and set your admin password. For production usage, we recommend using an external database, like MySQL or PostgreSQL. You can easily find a DBaaS (Database-as-a-Service) provider to host your data.

![drupal setup step 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zfz0nbpvq6fb10i9ty16.png)

Finally step, just wait for the complete installation...

![drupal setup step 4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/keweyhtbvoonrkgeciy8.png)

Well done! Your new Drupal website is now live on the cloud provider of your choice.

![drupal website homepage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/68vxp4rkrqkkxyupuf30.png)

You can go in the "**Log in**" section of your published website, enter your admin credentials and try the awesome features offered by the Drupal platform 🚀

![drupal website homepage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x930vxeoafn90kna8s28.png)

Note that you can easily import, export, and synchronize your Drupal configuration from the administration page. See details on the [Drupal documentation](https://www.drupal.org/docs/configuration-management/managing-your-sites-configuration).

## Go further with dedicated resources

If you need a powerful resource with more vCPU, RAM or storage to host your production server, you can upgrade dynamically to a dedicated resource from your [ScaleDynamics Console](https://console.scaledyn.com/). As shown below it's as simple as a few clicks.

![Upgrade to dedicated](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o91zuvj5ag49elxiydcn.gif)

## What’s next

At this stage, you have an awesome Drupal website published on cloud with Docker.

You can learn more on the [ScaleDynamics documentation](https://docs.scaledynamics.com/), like how to get the logs of your server, use a custom domain, implement a CI/CD pipeline, etc.

Enjoy!