Skip to main content
Image
1920x600-14.jpg

How To Host Drupal 8 on AWS?

article publisher

Gaurav Kapoor

Drupal

Hosting your Drupal website on AWS enhances the performance, security, and flexibility of your website in a cost-friendly budget. In this tutorial, you will learn to host Drupal on AWS and also how to migrate an existing website to AWS.

Amazon logo   Drupal logo

Literally speaking, it is a most advanced content management system that works perfectly if it is backed by a robust server infrastructure like Amazon Web Services (AWS).

Merits and demerits of hosting approach.

Single Server 
Suitable for small websites with less traffic.
Resource management becomes difficult if the load on the website increases.

Distributed System
Suitable for websites with large traffic.
Easy resource management. Spend only on components which need extra resources.

Before starting the tutorial, you need to have access to following services. 

  • EC2 instance 
  • RDS Instance 
  • S3 Bucket 

AWS provides various services which can be used to host Drupal 8 in a distributed environment.

Let’s start with the hosting process.

  • EC2 instance

    STEP 1 - Launch an EC2 instance of the desired configuration. You can learn to launch EC2 here. 

    STEP 2 -  After successful completion of Step 1, install LEMP stack and PHP libraries, so Drupal works smoothly. 

    STEP 3 -  Next, download the latest stable release of Drupal and place it in the server directory. 

    STEP 4 -  Configure virtual host and other nginx settings and then hit your website from the browser.
    Amazon EC2 logo Drupal installation profile; choosing the installation profile as 'standard'

    Before moving further, make sure you are able to access your Drupal installation.

    Since you have set up the codebase on an EC2 server, you now need to prepare RDS instance to store the database on your website.
     

  • RDS Instance 

    STEP 5 - Launch an RDS instance with the desired configuration. Official documentation to launch an RDS instance can be found here. Make sure that RDS instance and EC2 instances are in the same virtual private cloud or at least same geographical proximity for an ideal performance. In case they are not, your application will suffer from high latency.


    STEP 6 - In case you have to do minor changes in MySQL configuration, make sure it works effectively with your Drupal installation. Points you will have to focus on, are memory limits, timeouts, and query cache. All these can be configured by parameters group of RDS.
     

    STEP 7 -  You can access your domain / IP for RDS instance, database name and password from your AWS dashboard. Now go back to your Drupal installation and input the RDS configuration in database settings.

    Drupal database configuration; selecting the database username and entering password

    In case you are facing an error connecting to the database, check your credentials. Also, try accessing RDS from your local environment to make sure that it has started properly.
    Amazon S3 logo

  • S3 Bucket 

    STEP 8 - Once your Drupal site is running with the current setup, you can replace file system with your S3 bucket. S3 bucket is an inexpensive alternative for file storage by AWS.


    STEP 9 - To use S3 bucket with Drupal 8, follow these instructions.

  • Create one S3 bucket from AWS dashboard. Make sure it is publicly readable and writable

  • Obtain Access key and secret through IAM roles of AWS.

  • Now go back to EC2 instance and install S3FS module using composer. It is important to install it using composer as it requires AWS PHP SDK to function.
     

    STEP 10 - Once you have installed and enabled the module, you have 2 ways of using it:
    A. To use S3 for specific fields like file or images field. Follow these steps:

  • Configure all the S3 settings such as bucket name, region, access key and secret key from /admin/config/media/s3fs.

  • While creating a field choose S3 as default storage for the file. Now when you will add node all the files added through that field will be stored in S3 bucket.

    B. Replace your entire public file system with S3.
    Edit your settings.php and then add the following configuration.

    Now all the Drupal resources i.e Images, aggregated CSS and JS etc will be served from S3 bucket instead of the web server.

    In case you face some trouble related to CSS and JS files path, ‘README’ file for the module is the solution to all those issues.


    The following steps are to help you migrate your existing website to AWS:

    STEP 1 - Git clone your code repository or use SFTP to transfer your code files to EC2 server.

    STEP 2 - Import database into RDS and change credentials in a settings.php file.

    STEP 3 - Set up the S3 bucket and then run Drush command (drush s3fs-copy-local ) to copy all the files from current files folder to S3 bucket. 

This is a small guide on how you can install Drupal 8 on AWS. 

Subscribe

Ready to start your digital transformation journey with us?

Related Blogs

SDC: Integrating Storybook & Single Directory Component

Integrating SDC With Storybook OpenSense Labs

Today, we will talk about about Drupal Single Directory Components or SDC and Storybook. Single Directory Components in Drupal allows you…

RFP: How To Create An RFP For Open Source Solutions?

RFP OpenSense Labs

A good Request for Proposals (RFP) or Call for Proposals (CFP) clearly states the goals and expectations of your project and sets the…

Drupal 7 End Of Life: Top Reasons You Should Migrate To Drupal 10

Drupal 7 End Of Life Cover Image OpenSense Labs

Drupal 10 was released in December 2022 and ever since, the community has been pushing its users to do Drupal 7 to 10 migration. As per…