Migrating a Drupal website from Pantheon to AWS

Introduction

Pantheon and AWS are one of the biggest CMS solution providers out there. One of our clients wanted us to help move their existing infrastructure to AWS from Pantheon. Migrating a Drupal website from Pantheon to  AWS involves a few complex steps that can be tricky to get a grasp on. In this guide, we give you the exact steps you need to take to migrate from Pantheon to AWS. 

Codebase and File Retrieval from Pantheon and Code Cleanup

Since the Encyclopedia is implemented in Drupal and hosted on Pantheon, we need to take a few basic steps before moving it to AWS.

  • Retrieve the latest codebase from Pantheon's Git repository
  • Download the database and media files
  • Since Drupal doesn't store absolute paths in the database, there's no need to run a search and replace in the database file 
  • Remove all Pantheon-specific settings from the codebase

  • Remove Pantheon-specific settings files and obtain a fresh settings.php file from the settings.local.php file. Update it accordingly, as Pantheon settings are also included in the settings file.

AWS Setup

1. Setting up the EC2 Instance

  • Instance Selection: Choose the appropriate Amazon EC2 instance type based on your application’s requirements, considering factors like CPU, memory, and storage needs. Common choices include t3.medium for smaller applications and m5.large for more demanding workloads.
  • Launching the Instance: Use the AWS Management Console or AWS CLI to launch a new EC2 instance. Configure the instance with the necessary security groups, VPC settings, and key pairs for SSH access.
  • Operating System Configuration: Select an appropriate AMI (Amazon Machine Image) for your operating system, such as Amazon Linux 2, Ubuntu, or CentOS. Install and configure essential software packages, including web servers (Apache, Nginx) and any other dependencies.

2. Database Setup (Using RDS is Optional)

  • RDS Configuration: If you opt to use Amazon RDS (Relational Database Service), choose the suitable database engine (MySQL, PostgreSQL, etc.). Configure the instance size, storage, and security settings. Enable automated backups and Multi-AZ deployment for high availability.
  • Manual Database Setup: Alternatively, set up the database directly on an EC2 instance. Install the database software, create necessary databases, and configure security settings. Ensure regular backups and implement replication for redundancy.

3. Setting Up Load Balancer

  • Elastic Load Balancer (ELB): Set up an Application Load Balancer (ALB) or Network Load Balancer (NLB) to distribute incoming traffic across multiple EC2 instances. Configure listeners, target groups, and health checks to ensure efficient traffic distribution and fault tolerance.
  • Security Configurations: Set up security groups and network ACLs to control access to your load balancer and backend instances. Enable SSL termination at the load balancer level for secure communication.

4. Setting Up Auto Scaling

  • Auto Scaling Groups: Create Auto Scaling groups to automatically adjust the number of EC2 instances based on traffic patterns and load. Define scaling policies and set thresholds for scaling out (adding instances) and scaling in (removing instances).
  • Monitoring and Metrics: Utilize CloudWatch to monitor metrics such as CPU utilization, request counts, and latency. Configure alarms to trigger scaling actions based on predefined criteria.

5. Codebase Setup with Git

  • Repository Configuration: Set up a Git repository to manage your codebase. Use services like AWS CodeCommit, GitHub, or Bitbucket for version control.
  • Deployment Automation: Implement Continuous Integration/Continuous Deployment (CI/CD) pipelines using AWS CodePipeline or other CI/CD tools. Automate the deployment process to ensure consistent and error-free code deployments.

6. File System Configuration

  • Amazon EFS: Use Amazon Elastic File System (EFS) for shared file storage across multiple EC2 instances. Configure EFS to automatically scale and provide high availability and durability.
  • S3 for Static Assets: Store static assets (images, videos, documents) in Amazon S3. Configure appropriate bucket policies and lifecycle rules for efficient storage management.

7. SSL Setup

  • SSL Certificates: Obtain SSL certificates from AWS Certificate Manager (ACM) or third-party providers. Configure the certificates on your load balancer to enable HTTPS for secure communication.
  • Redirects and Security Headers: Set up HTTP to HTTPS redirects and configure security headers (HSTS, Content Security Policy) to enhance the security of your web application.

8. Caching Setup (CloudFront)

  • CloudFront Distribution: Set up Amazon CloudFront as a Content Delivery Network (CDN) to cache and deliver static and dynamic content with low latency. Configure origins, behaviors, and cache settings to optimize performance.
  • Cache Invalidation: Implement cache invalidation strategies to ensure that updates to your content are reflected promptly across the CDN.

Codebase and DB Setup in AWS

Import Database:

  • If using RDS, create a new database and user. 
  • Import your Drupal database dump using MySQL -u username -p database_name < database_dump.sql
  • Retrieve the database details to add them in Drupal settings file such as:some text
    • Host or IP
    • DB name
    • Username
    • Password

Codebase:

We made some changes to the codebase while setting it up on AWS. Using Git is always a lifesaver for managing Drupal code. Here are a few things to do:

  • Get a fresh Git repository.
  • Add the code to the repository.
  • Update database settings and file settings in the settings.php file.
  • Run composer update to install all dependencies.
  • Commit the changes to the Git repository.
  • Deploy the code to the environment.

CI/CD setup

We will deploy a CI/CD pipeline on Jenkins, integrated with the client’s GitHub repository and hosted on AWS. This setup includes automated builds and tests triggered by webhooks on code commits and pull requests, with automated deployments for development and staging environments and a manual build process for production releases. This approach enhances collaboration, improves code quality, and accelerates delivery cycles.

Once everything is set up correctly, the Drupal site should be up and running. If not, we will need to debug the issues and ensure everything is working properly.

Launch Process 

DNS setup process (These records should be pointed at the time of the site launch)

The site  URL should point to the relevant IPs and data points - 

       CNAME Records

  Name: @

Value: d3n8adgtj2ul2a.cloudfront.net

Additional DevOps process

  • Setup the domain in the new environment
  • Setup redirect rules in ALB
  • SSL certificate validation process requires updating the CNAME record on the domain's cPanel within 72 hours after the creation of a new certificate.

Post Launch Items

  • Smoke Testing

After launching on AWS, perform comprehensive smoke testing to ensure the core functionalities of the website are operating correctly. This involves verifying the site's basic functions such as loading the homepage, navigating between key pages, submitting forms, and confirming that there are no immediate critical errors that might affect user experience or business operations.

  • Run a Spider and Make Sure All the URLs Pointed to the Domain

Use a web crawler or spider tool to scan the entire website and confirm that all URLs are correctly pointing to the new AWS-hosted domain. This step ensures that there are no broken links or references to the old Pantheon URLs, which could lead to 404 errors and negatively impact SEO.

  • GA/GTM - Make Sure Analytics Are Going Through Properly

Verify that Google Analytics (GA) and Google Tag Manager (GTM) are correctly implemented and tracking data as expected. This includes checking that all tracking codes are firing on the relevant pages and that data such as page views, events, and conversions are being recorded accurately in GA.

  • Check All Tracking Scripts

Review all tracking scripts embedded in the website to ensure they are functioning properly. This includes third-party tracking scripts for marketing, advertising, and user behavior analysis. Make sure these scripts are updated with the new domain settings and are recording data without any issues.

  • Enable Indexing

Ensure that the website is set to allow search engines to index its content. This involves checking the settings in the website’s backend and ensuring that any "noindex" tags used during the development and testing phases are removed. Proper indexing helps in making the new site visible in search engine results.

  • Check if the New Robots.txt Is Being Indexed Properly

Review the robots.txt file to ensure it is correctly configured and being indexed by search engines. This file guides search engine crawlers on which pages or sections of the site to index and which to avoid, and must reflect the new site's structure and policies.

  • Check sitemap.xml

Examine the sitemap.xml file to ensure it includes all the correct URLs of the new site and is accessible to search engines. The sitemap helps search engines understand the site's structure and ensures that all pages are crawled and indexed efficiently.

  • Redirects

Validate that all necessary redirects from the old Pantheon site to the new AWS-hosted site are properly configured. This includes setting up 301 redirects for all old URLs to their new counterparts to maintain SEO equity and provide a seamless transition for users accessing the old URLs.

Backup and Security

  • Regular Backups:
    • Set up automated backups for both the database and the file system.
    • Use AWS Backup or third-party solutions.
  • Security Best Practices:
    • Regularly update the software to patch vulnerabilities.
    • Use IAM roles and policies to restrict access.

Conclusion

While challenging at first glance, as long as these steps are followed through and the best practices pre migration and post migration are thoroughly maintained, you should have your Drupal site easily migrated from Pantheon to AWS.

If you enjoyed this post and want more, please feel free to join us on LinkedIn, X and Facebook.

Related Insights

WordPress Hosting Options: SiteGround vs. WP Engine

We compare the DevOps features of two WordPress hosting products: SiteGround and WPEngine.

Venkat reddy

DevOps

Subscribe to our newsletter