Close
  • Home
  • About
  • Services
ukr
  • Projects
  • Blogs
  • Contact
  • Menu

Setting up Magento 2.4.2 on AWS EC2 with Docker: A Comprehensive Guide

By Ujjal ray on 1 December 2023 • 10 mins read
Scroll

Introduction

Setting up Magento on a cloud server requires careful configuration to ensure smooth development and deployment. This comprehensive guide will walk you through the process of configuring an AWS EC2 instance, installing Docker, and deploying Magento 2.4.2. Follow these steps to create a robust development environment.

AWS EC2 Server Configuration

  1. Connect to the Server:

    ssh -i "AdobeCommerce-Dev.pem" ec2-user@<IP>
  2. Update the Server:
    sudo yum update -y

  3. Install Docker:
    sudo yum install -y docker
    sudo service docker start
    sudo usermod -a -G docker <username>  # Replace `<username>` with your username
    docker info

  4. Unzip Files:
    sudo yum install unzip
    unzip <folder_name>

  5. Install Git:
    sudo yum install git

  6. Reset Docker Images:
    docker system prune --volumes

  7. Remove Directory:
    sudo rm -rf <dir>

 

Magento Installation Using Docker

 

  1. Clone the Git Repo:
    git clone https://github.com/RayUjjal/magento2.git

  2. Create .env File:

    • Clone .env.example to .env and add the necessary database details.

     

  3. Build and Start Docker Containers:
    docker-compose build
    docker-compose up

  4. Access Docker PHP Terminal:
    docker exec -it <container_image_name> bash

  5. Magento Installation:
    cd var/www/html
    composer create-project --repository-url=https://repo.magento.com/magento/project-community-edition <project-dir>

  6. File Permissions:
    cd /var/www/html/magento_hamilton
    find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
    find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
    chown -R :www-data .
    chmod u+x bin/magento

  7. Magento Installation Commands:
    bin/magento setup:install --base-url='<baseurl>' --db-host=db --db-name=<db-name> --db-user=<db-user> --db-password=<db-pass> --admin-firstname=<firstname> --admin-lastname=<lastname> --admin-email=<email id> --admin-user=<username> --admin-password=<password> --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --search-engine=elasticsearch7 --elasticsearch-host=search --elasticsearch-port=<es port>

  8. PWA Metapackage Installation:
    composer config minimum-stability dev
    composer config repositories.ext path "./ext/*/*/*"
    composer require magento/pwa

  9. Install Goomento Page Builder:(optional)
    composer require goomento/module-page-builder
    php bin/magento module:enable Goomento_PageBuilder

  10. Enable Magento Modules:
    php bin/magento module:enable --all

  11. Disable Two-Factor Authentication:
    php bin/magento module:disable Magento_TwoFactorAuth

  12. Reindexing and Cache Clear:
    php bin/magento indexer:reindex
    php bin/magento cache:flush

  13. Magento Admin URL:

    • Access the admin panel using the URL provided in magento2-docker-main/public_html/<root dir>/app/etc/env.php.

     

  14. Database Dump:
    mysqldump -u <db user> -p <db password> > <filename>.sql
    sudo docker cp -a <docker-container-name>: <filename>.sql /home/ec2-user/<folder path>

  15. Magento Module Enable/Disable:
    bin/magento module:enable <Module1>
    bin/magento module:disable <Module1>
    php bin/magento setup:upgrade

  16. Magento Deploy Mode:
    bin/magento deploy:mode:set developer

  17. Cron Jobs:
    crontab -l
    bin/magento cron:install
    bin/magento cron:run

 

Conclusion

 

Congratulations! You have successfully set up Magento 2.4.2 on AWS EC2 using Docker. This guide covers the essential steps for a seamless installation and configuration process. Keep this handy for future reference, and happy developing!

ukr