How to Host and Deploy Drupal Sites using Cloudways

This page contains affiliate links, meaning we get a commission if you decide to make a purchase through our links, at no cost to you. Please read our disclosure for more info.

Cloudways is a managed cloud hosting provider which allows you to host and deploy Drupal sites on popular cloud platforms. They don’t host your site, instead you choose a cloud provider, i.e., DigitalOcean, Linode, AWS and so on.

Cloudways server providers

The benefit of using Cloudways is that you can start on a cheap server and upgrade as needed. You get the same features if you spend $20 or $100 per month. As your site gets more traffic you can scale up to a faster server.

The server provisioning and application management is all done via the Cloudways platform. For example, if you use DigitalOcean, you won’t have to create a separate account to manage the server. You can do everything via Cloudways platform.

The servers come configured with PHP, Apache, MariaDB, Varnish, Redis (uninstalled by default) and so on.

Once provisioned you’ll be able to host an unlimited number of Drupal sites on a single server. You’ll need to make sure your server has enough resources, i.e., RAM and CPU.

Other hosting platforms charge per site and traffic. Cloudways only charger per server and you can install as many websites as the server and bandwidth can handle.

In this tutorial, you’ll learn how to install and deploy a Drupal site on Cloudways.

We’ll cover how to install and run Drupal in two ways:

  • How to manually install Drupal via SSH
  • How to Deploy Drupal using GitHub

Cloudways doesn’t have a one-click install for Drupal. You will need to be comfortable with Composer and using SSH to get into a server. If you want to deploy your Drupal site via Git then you’ll need to be comfortable using GitHub.

Register an Account

Before we can begin, go and create an account on Cloudways.

1. Click on “Start Free” in the top right corner.

2. Fill out the sign up form and click on “Start free”.

Cloudways registration form

3. Then go and configure your billing details.

Create Server

Once you’re logged and configured your billing details it’s time to create a server.

1. Go to the Servers page and click on “Add server” in the right corner.

Cloudways server listing

2. From the “Select your Application” drop-down, select “Custom App”.

Cloudways application selector

NOTE: You can host Drupal and WordPress sites on the same server.

3. Add a name for your application, server and select a project.

Select Cloud Platform

Now you’re ready to choose a cloud provider, server size and location. Each provider offers different options but DigitalOcean is the easiest to get started with. All you have to do is select a server size and location.

1. Select a server size and location.

NOTE: The pricing will be shown at the bottom of the browser.

2. Click “Launch now” when you’re ready.

Then the server will be provisioned and it’ll take about 5-10 minutes to be ready.

Drupal Application

Click on “Applications” in the header and you should see the application that was created when the server was provisioned.

NOTE: You can add another application on the same server by clicking on “Add Application”.

Create Application User

You can SSH and FTP into the server using the master credentials which will allow you to manage any application on the server. But it’s recommended that you create a separate user account for the application.

Learn more about the difference between master and application credentials.

Cloudways allows you to create accounts for just specific applications.

1. Click into the application on Cloudways and on “Access Details”, enter a username and password into “Application Credentials”. Then click on “Add”.

2. Click on “Application Settings” on the left and enable “SSH ACCESS”.

Test your SSH access by opening your terminal and running the following command:

ssh [email protected]_IP

Replace SERVER_IP with your actual IP address which you can get from “Access Details”.

If you try and log in and get “Shell access is disabled !Connection to SERVER_IP closed.” This means that you haven’t enabled SSH access as mentioned above.

Install Drupal via SSH

To install Drupal via SSH, make sure you have an application set up and you can SSH into.

1. SSH into your application.

ssh [email protected]_IP

2. Make sure you’re in the “~/public_html” directory and that the directory is empty. You may have to delete a index.php file.

Type the following to delete:
rm index.php

3. Run the following command Composer command within the “~/public_html” directory:

composer create-project drupal/recommended-project ./

4. After running the Composer command, we need to change the webroot settings in the application on Cloudways.

Go to “Application Settings” and change the WEBROOT from “public_html” to “public_html/web”.

5. Click on the application URL by going to “Access Details” and clicking on the external icon under “Application URL”.

If you go to the URL and see “Getting Started With Cloudways PHP Hosting”. Then you’ll have to purge the Varnish cache.

Go to your server then click on “Manage Services”, then click on the PURGE button on the Varnish row.

6. Now go ahead and install Drupal. Use the provided database username and password on the “Access Details” page.

7. Once installed you will have a working Drupal site.

Managing Drupal core and Modules

To update Drupal core and install modules and themes, you’ll need to SSH into the server to run Composer commands.

Refer to Using Composer to Install Drupal and Manage Dependencies document to learn more about.

Deploy Drupal via Git

In the section above, we looked at how to install Drupal by using SSH to get into the server and running Composer to download Drupal.

Now I want to show you how to use GitHub to deploy changes to Cloudways.

I’m going to assume you already have a server. If you don’t, then follow the steps in “Create server” (TK – link back to create server section).

Create Application

1. In Cloudways, go to Applications and click on “Add Application” and select your server.

2. Select “Custom App” from PHP drop-down, give your app a name and select a project then click on “Add Application”.

NOTE: You can use an existing application if you like.

Create Local Drupal Version

Now we need to create a Git repository with our Drupal code.

We’ll prepare the code locally first then push it into GitHub. If you already have an existing Drupal code base stored in GitHub you can skip this step.

1. Open up your terminal and run the following Composer command:

composer create-project drupal/recommended-project PROJECT_NAME

Replace PROJECT_NAME with a folder name.

2. Add a .gitignore file into the folder with the following content.

You’ll need this .gitignore file because we don’t want to store the vendor or settings in the repository.

3. Go to GitHub and create a repository and push your files into it.

Configure SSH Key in GitHub

To deploy using GitHub we need to configure a few things in Cloudways.

1. Go to the application and click on “Deployment Via Git” and click on “Generate SSH Key”.

2. Click on “View SSH Key” and copy the key.

3. With the copied key, go into GitHub, Settings, “Deploy key” and add the key.

4. Get the SSH URL for the git repository from GitHub.

5. Then go back to “Deployment Via Git” in Cloudways and paste the URL in “Git Remote Address” and click on Authenticate.

6. Select which branch you want to deploy from Branch and the “Deployment path” with public_html.

To deploy changes simply click on “Start Deployment”.

Run Composer on Server and Install

You’ll need to SSH into the application and delete the default index.php and run composer install.

1. SSH into the application and delete the default index.php file within (~/public_html).

rm index.php

Do not delete the index.php in the web folder.

NOTE: If this is a new application then create an application account and enable SSH (TK add link to Create Application User).

2. Run composer install within the public_html folder

composer install

3. In Cloudways, go to “Application Settings” and change the webroot settings to “public_html/web”.

4. Click on the application URL by going to “Access Details” and clicking on the external icon under “Application URL”.

5. Now go and install Drupal. Use the provided database username and password on the “Access Details” page.

NOTE: If you’re having trouble then please refer to the Cloudways documentation.

Configuration Management

One benefit with deploying your Drupal site via GitHub is you can store your configuration files in the repository. I won’t cover how configuration management works because that’s out of the scope for this tutorial. But I’ll show you what’s required to configure it.

Drush will be required for the workflow so make sure you download drush using Composer; composer require drush/drush.

You’ll need to edit the settings.php on Cloudways and your local version to store the configuration files in a different folder. By default, Drupal will store the configuration in the files directory which is ignored using the .gitignore file.

1. Open your settings.php locally and scroll to the bottom and change the “config_sync_directory” setting.

$settings['config_sync_directory'] = '../config/sync';

This will store the files outside of the web directory in a config folder.

2. SSH into the application edit the settings.php file and add “$settings[‘config_sync_directory’]” at the bottom.

cd web/sites/default/
chmod 664 settings.php
vim settings.php
# Edit the file
chmod 444 settings.php

Edit Settings File using FileZilla

If you prefer, you can edit the settings.php using an FTP client.

1. SFTP into your application. Follow the Cloudways instructions.

2. Go to public_html/web/sites/default.

3. Change the permission for settings.php to 664. First right click on the “File permissions…”

4. Change permission to 664.

5. Edit the file.

6.  Then change the permission back to read-only.

Configuration Management Workflow

Locally edit your Drupal site and when you’re ready run; drush cex. This will export the configuration files into config/sync.

Then commit the files into git, then go onto Cloudways and click on “Start deployment”.

To import the changes on the server you’ll need to SSH into the application and run drush cim.

Run Drush Commands on Server

You’ll need to execute Drush from the vendor directory to run Drush on the server.

Instead of just running drush, it’ll have to be ./vendor/bin/drush. Assuming you’re in the ~/public_html folder.

Private Files

By default Drupal stores files in a public folder, i.e., “sites/default/files”. Drupal has the ability to store files in a private folder which can’t be publicly accessed.

Let’s configure the private folder on Cloudways.

1. SSH or use SFTP and create a folder in public_html called “private_files”. The path should be public_html/private_files.

2. Edit the settings.php and add $settings['file_private_path'] = $app_root .'/../private_files'; at the bottom of the file.

3. Make sure you clear the Drupal site cache by running drush cr.

4. If you go to your Drupal site and then Configuration -> “File system”, you should see private local files as an option in the “Default download method”.

Add /private_files into the .gitignore file.

Deployment Process

The deployment workflow will work as follows:

  1. Commit file and configuration changes into your repository.
  2. Go to “Deployment Via Git” in Cloudways and click on Pull to download the latest changes.
  3. SSH into the application and run composer install if required and drush cim to import configuration changes.

NOTE: Cloudways doesn’t support post deployment commands. You’ll have to manually run commands after you’ve pulled the latest changes.

Redis

Redis can be used to speed up your Drupal site by storing the cache tables in memory instead of the database.

Enable Redis

You’ll need to install Redis on your server which can be done free of charge.

Go to your server on Cloudways, then click on “Settings & Packages”, Packages then click on Install.

Once installed you should see it in the “Manage Services” section.

Configure Redis Module

Now that we have Redis running on the server. We need to configure Redis in Drupal.

You’ll need to use the Redis Drupal module for this.

1. Download the Redis module using Composer:

composer require drupal/redis

Commit and deploy the changes.

2. Make sure you install the module before adding the settings below.

3. Configure Redis options in settings.php.

$settings['redis.connection']['interface'] = 'PhpRedis';
$settings['redis.connection']['host']      = '127.0.0.1';
$settings['cache']['default'] = 'cache.backend.redis';

$settings['container_yamls'][] = 'modules/contrib/redis/example.services.yml';

Refer to the Redis module README.txt for more information.

4. Clear the site cache and lookout for any errors.

If you go to the “Status report” page (/admin/reports/status) in Drupal, you should see:

You can also go to the Redis status page. Reports -> Redis (/admin/reports/redis).

You can SSH into the server and run the following command:

redis-cli monitor

Then navigate around the site you should see requests returning. This means Redis is working.

Staging Sites

Cloudways allows you to clone a website and use it as a staging site.

Staging sites are useful for testing new modules and building new functionality.

1. You can clone a site from the “Applications” page by clicking on the options button, then click “Clone App/Create Staging”.

Or if you’re in the application you want to clone, click on the option button on the bottom right, then click on “Clone App/Create Staging”.

2. Select which server you want to clone the site to. Then check “Create as Staging”.

If you go to the Applications page you should see a new application with the label of staging.

Push and Pull Changes

You can push and pull file and database changes between the live and staging site.

Go into the staging application then click on “Staging Management”.

Learn more about creating a staging site on Cloudways.

Cron Jobs

Cron can be configured via the Cloudways platform.

1. First you’ll need to get the cron URL. Go into your Drupal site then go to Configuration -> Cron (/admin/config/system/cron).

Copy the URL in the highlighted section.

2. Go into Cloudways and the application. Click on “Cron Job Management” then “Add New Cron Job”.

3. Click on “Common Settings” and select how often you want to run cron. “Once an hour” is a common option.

4. Scroll down to Type and select cURL.

5. And paste the Cron URL in the URL field.

Then click on Submit.

6. You can see if cron is running by going to Reports -> “Recent log messages” (/admin/reports/dblog) and filter the logs by cron.

Change PHP Memory Limit

Go into the server, “Settings & Packages”, then change the “Memory Limit” value.

Change PHP Version

Go into the server, “Settings & Packages”, click on Packages. Click on the pencil icon next to PHP.

Migrate Database and Files

To import a different database, go into the application on Cloudways and click on the “Launch database manager” from within “Access Details”.

Click on Import and follow the steps.

To import files, you can use an FTP client or SSH.

FAQ

Q: I can’t SSH into the application? I get “Shell access is disabled”.

You must enable SSH access via the “Application Settings”.

Q: I get a “mkdir(): Permission denied” when I run Composer outside of “public_html”?

User do not have write permission outside of public_html and private_html.

Q: I went to the application URL but I don’t see Drupal?

First try to clear the Varnish cache. Go to the server and click into “Manage Services”, then click on Purge.

Leave a Comment

You have to agree to the comment policy.

This site uses Akismet to reduce spam. Learn how your comment data is processed.