DEV Community

Nicolas PENNEC for ScaleDynamics

Posted on • Originally published at docs.scaledynamics.com

How to deploy Drupal on cloud with Docker

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 is one of the most popular CMS (Content Management Software).
Build with PHP, 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.

Drupal logo

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:

Init your Drupal application

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

mkdir drupal-app
cd drupal-app
Enter fullscreen mode Exit fullscreen mode

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 downloaded from Docker Hub:

# drupal-app/Dockerfile

FROM drupal:latest
EXPOSE 80
Enter fullscreen mode Exit fullscreen mode

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 (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. 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.

Environment creation

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:

// drupal-app/warp.config.js

module.exports = {
  docker: "drupal-app",
};
Enter fullscreen mode Exit fullscreen mode

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 and available on the official npm registry: https://www.npmjs.com/package/warp

Install the library as development dependency in your project:

npm init -y
npm install --save-dev warp
Enter fullscreen mode Exit fullscreen mode

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

npm install -g warp
Enter fullscreen mode Exit fullscreen mode

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:

npx warp --help
Enter fullscreen mode Exit fullscreen mode

See more about SDK 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:

npx warp login
Enter fullscreen mode Exit fullscreen mode

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:

npx warp deploy
Enter fullscreen mode Exit fullscreen mode

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

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 by example.

npx warp deploy --project <project-name> --env <env-name>
Enter fullscreen mode Exit fullscreen mode

See more about warp deploy command in the SDK documentation

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

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

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

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

drupal setup step 4

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

drupal website homepage

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

Note that you can easily import, export, and synchronize your Drupal configuration from the administration page. See details on the Drupal documentation.

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. As shown below it's as simple as a few clicks.

Upgrade to dedicated

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, like how to get the logs of your server, use a custom domain, implement a CI/CD pipeline, etc.

Enjoy!

Discussion (0)