Introduction

Web Host Manager (WHM) is a powerful tool for managing web hosting accounts on a server. By integrating Elastic File System (EFS) for data storage and Amazon S3 for backups, you can enhance reliability and scalability. This guide outlines the steps to set up WHM with EFS and configure S3 for automated backups.

Prerequisites

Before starting, ensure you have:

  • An AWS account with appropriate permissions.
  • Basic knowledge of WHM administration.
  • Familiarity with Amazon EFS and S3.

Step 1: Set Up Amazon EFS

  1. Create an EFS File System:
    • Go to AWS Management Console and navigate to Amazon EFS.
    • Click “Create file system” and configure it with the desired settings (VPC, availability zones, performance mode, etc.).
    • Note down the file system ID (fs-xxxxxxxx).
  2. Mount EFS on EC2 Instance:
    • Launch or select an EC2 instance suitable for WHM.

Attach the EFS file system to the instance using the Amazon EFS mount helper.

sudo yum install -y amazon-efs-utils

sudo mkdir /mnt/efs

sudo mount -t efs fs-xxxxxxxx:/ /mnt/efs

  • Ensure EFS mounts automatically on instance reboot by adding an entry in /etc/fstab.

Step 2: Install WHM on EC2 Instance

  1. Launch an EC2 Instance:
    • Choose an instance type compatible with WHM requirements (e.g., CentOS or Amazon Linux).
    • Configure security groups to allow necessary ports (2087 for WHM, 22 for SSH, etc.).
  2. Install WHM:
    • Connect to your EC2 instance via SSH.

Follow the official cPanel installation guide to install WHM:

cd /home && curl -o latest -L https://securedownloads.cpanel.net/latest && sh latest

  • Complete the installation by following the prompts.

Step 3: Configure WHM to Use EFS

  1. Move WHM Data to EFS:
    • Stop relevant WHM services (systemctl stop cpanel.service).

Move WHM data directories to EFS:

sudo mv /var/cpanel /mnt/efs/

sudo ln -s /mnt/efs/cpanel /var/cpanel

  1. Update WHM Configuration:
    • Edit WHM configuration files to point to EFS locations.
    • Restart WHM services (systemctl start cpanel.service).

Step 4: Set Up S3 for Automated Backups

  1. Create an S3 Bucket:
    • Go to AWS S3 in the Management Console.
    • Click “Create bucket” and follow the prompts to create a new bucket.
  2. Configure Backup Script:

Create a backup script on your EC2 instance to periodically backup WHM data to S3:

#!/bin/bash

tar -zcvf /tmp/whm-backup-$(date +%Y%m%d-%H%M%S).tar.gz /var/cpanel

aws s3 cp /tmp/whm-backup*.tar.gz s3://your-bucket-name/

rm /tmp/whm-backup*.tar.gz

  • Schedule this script using cron to run at desired intervals (crontab -e).

Step 5: Testing and Maintenance

  1. Test Backup and Restore:
    • Manually trigger backups and verify files are stored in the S3 bucket.
    • Test restoring backups to ensure data integrity and functionality.
  2. Monitor EFS and S3 Usage:
    • Set up CloudWatch alarms for EFS and S3 to monitor usage and performance.
    • Regularly review logs and metrics to ensure smooth operation.

Conclusion

By integrating Amazon EFS for data storage and S3 for backups, you’ve enhanced the reliability and scalability of your WHM setup. This approach ensures that your data is securely stored and readily available, backed by AWS’s robust infrastructure.

Implementing these steps effectively combines WHM’s powerful hosting management capabilities with AWS’s scalable storage solutions, providing a robust environment for hosting and managing websites.