All Products
Search
Document Center

Elastic Compute Service:Build a Magento 2 e-commerce website on an Ubuntu instance

Last Updated:May 15, 2026

Deploy Magento 2, an open-source e-commerce platform, on an ECS instance running Ubuntu with NGINX, MySQL, OpenSearch, and Composer.

Note

See the Adobe Commerce official website for details about Magento 2.

Background

This topic uses an ECS instance with the following configurations:

  • Instance type: ecs.c7.large

  • Operating system: Ubuntu 22.04 64-bit public image

  • CPU: 2 vCPUs

  • Memory: 4 GiB

    Note

    Magento 2 requires at least 4 GiB of memory.

The following software versions are required per the Magento 2 official documentation:

  • Composer 2.7: Manages the Magento 2 codebase and third-party dependencies.

  • OpenSearch 2.12: Provides product search, including filtering and relevance sorting.

  • MySQL 8.0: Stores business data such as products, orders, and customer records.

  • PHP 8.3: Executes application logic and communicates with databases and other services.

  • NGINX 1.24: Serves static files and reverse-proxies dynamic requests to PHP-FPM.

Prerequisites

  1. Obtain your personal keys from Adobe Commerce.

    image

  2. A public IP address is automatically assigned to the ECS instance. Alternatively, an elastic IP address (EIP) is associated with the ECS instance. For instructions on how to enable public bandwidth, see Enable public bandwidth.

  3. Port 22 is open in an inbound security group rule. See Add a security group rule.

  4. Docker is installed on the ECS instance. See Install Docker.

  5. An LNMP stack (Linux, NGINX, MySQL, and PHP) is deployed. See Deploy an LNMP stack.

    Note
    • Required versions: NGINX 1.24, MySQL 8.0, and PHP 8.3.

    • Adjust version numbers in the following steps accordingly.

Procedure

Step 1: Install PHP extensions

  1. Install the core PHP package and extensions.

    1. Install the core PHP package with bundled extensions.

      sudo apt-get install php8.3-cli php8.3-common php8.3-fpm php8.3-mysql php8.3-zip php8.3-gd php8.3-curl php8.3-intl php8.3-mbstring php8.3-soap php8.3-xml php8.3-bcmath php8.3-sqlite3 php8.3-opcache
    2. Install additional extensions.

      sudo apt-get install php8.3-bcmath php8.3-curl php8.3-gd php8.3-intl php8.3-mbstring php8.3-soap php8.3-xml php8.3-zip php8.3-sqlite3
    3. Restart NGINX to apply the changes.

      sudo systemctl restart nginx  
  2. Configure php.ini.

    1. Open the php.ini files.

      sudo vim /etc/php/8.3/fpm/php.ini
      sudo vim /etc/php/8.3/cli/php.ini
    2. Update the following settings, then save and close the files.

      memory_limit = 2G
      max_execution_time = 1800
      zlib.output_compression = On
    3. Restart PHP-FPM.

      sudo systemctl restart php8.3-fpm

Step 2: Create a Magento2 database

  1. Connect to MySQL.

    mysql -u root -p

    Enter the MySQL root password when prompted.

  2. Create and configure a database. In this example, the database and username are both magento.

    CREATE DATABASE magento;
    CREATE USER 'magento'@'localhost' IDENTIFIED BY 'magento';
    GRANT ALL PRIVILEGES ON magento.* TO 'magento'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
  3. Verify the database.

    mysql -u magento -p
    Note

    If the MySQL monitor appears, the database is created. If an error occurs, re-run the preceding statements.

Step 3: Download and install OpenSearch

  1. Before installing OpenSearch with Docker, complete the following tasks:

    1. Disable memory paging and swapping to improve performance.

      sudo swapoff -a
    2. Increase the memory map limit for OpenSearch.

      1. Open sysctl.conf.

        sudo vi /etc/sysctl.conf
      2. Add vm.max_map_count=262144

      3. Verify the configuration.

        sudo sysctl -p
        cat /proc/sys/vm/max_map_count

        image

  2. Run OpenSearch in a Docker container.

    1. Pull the OpenSearch image.

      sudo docker pull opensearchproject/opensearch:2
    2. Deploy OpenSearch in a container to verify Docker works correctly.

      sudo docker run -d \
       -p 9200:9200 \
       -p 9600:9600 \
       -e "discovery.type=single-node" \
       -e "OPENSEARCH_INITIAL_ADMIN_PASSWORD=admin" \
       -e "plugins.security.disabled=true" \
       opensearchproject/opensearch:latest
      Note

      This example disables SSL on the HTTP and Transport layers for testing by setting plugins.security.disabled to true.

    3. Send a request to port 9200. The default credentials are admin/admin.

      sudo curl -k http://localhost:9200 -ku admin:admin

      Expected output:

      {
        "name" : "a937e018****",
        "cluster_name" : "docker-cluster",
        "cluster_uuid" : "GLAjAG6bTeWE****_d-CLw",
        "version" : {
          "distribution" : "opensearch",
          "number" : <version>,
          "build_type" : <build-type>,
          "build_hash" : <build-hash>,
          "build_date" : <build-date>,
          "build_snapshot" : false,
          "lucene_version" : <lucene-version>,
          "minimum_wire_compatibility_version" : "7.10.0",
          "minimum_index_compatibility_version" : "7.0.0"
        },
        "tagline" : "The OpenSearch Project: https://opensearch.org/"
      }
  1. List running containers and copy the OpenSearch container ID.

    sudo docker container ls
  2. Configure NGINX as a proxy for OpenSearch.

    1. Verify that /etc/nginx/nginx.conf contains include /etc/nginx/conf.d/*.conf;.

      vi /etc/nginx/nginx.conf

      image

    2. Create the proxy configuration.

      1. Create the following configuration file.

        sudo vim /etc/nginx/conf.d/magento_es_auth.conf
        server {
           listen 8080;
           location /_cluster/health {
              proxy_pass http://localhost:9200/_cluster/health;
           }
        }
      2. Restart NGINX.

        sudo service nginx restart
      3. Check whether the proxy works:

        sudo curl -u admin:admin -i http://localhost:8080/_cluster/health?pretty

        Expected output:

        image

Step 4: Download and install Composer

  1. Install decompression tools.

    Composer requires unzip or p7zip for decompression.

    sudo apt-get install unzip
    sudo apt-get install p7zip-full
  2. Install Composer:

    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    php composer-setup.php
    php -r "unlink('composer-setup.php');"
  3. Move composer.phar to a PATH directory for global access.

    sudo mv composer.phar /usr/local/bin/composer
  4. Verify the Composer version.

    composer --version

Step 5: Download and install Magento2

  1. Create a Composer project with the access key pair obtained from Adobe Commerce. The project name is magento.

    cd /var/www/html/
    sudo composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento
  2. Enter your authentication key when prompted.

    Note
    • The authentication key is the private key obtained in the Prerequisites section.

    • The download may take 5 to 10 minutes.

    image

  3. Set file permissions.

    cd /var/www/html/magento
    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
  4. Install Magento 2.

    Install Adobe Commerce from the command line. In this example, db-host is localhost, and db-name, db-user, and db-password are all magento.

    sudo bin/magento setup:install \
      --base-url=http://196.****.*.1/ \ # Public IP address of the ECS instance
      --db-host=localhost \ # Database host
      --db-name=magento \  # Database name
      --db-user=magento \ # Database username
      --db-password=magento \ # Database password
      --admin-firstname=admin \ # First name of the backend administrator
      --admin-lastname=admin \ 
      --admin-email=cy****sper@email.com \ # Administrator's email address
      --admin-user=admin \ # Backend login username
      --admin-password=admin*** \ # Backend login password
      --language=en_US \ # Website language
      --currency=USD \
      --timezone=America/Chicago \
      --use-rewrites=1 \
      --search-engine=opensearch \ 
      --opensearch-host=localhost \
      --opensearch-port=9200 \
      --opensearch-enable-auth=1 \
      --opensearch-username=admin \
      --opensearch-password=admin \
      --opensearch-index-prefix=magento2
  5. After installation, output similar to the following is displayed.

    image

    The Magento Admin URI is the administrator backend URL, accessible after NGINX is configured. Example: http://47.****.**.72/admin_46i****.

  6. Configure NGINX forwarding.

    1. Create a Magento 2 configuration file.

      sudo vim /etc/nginx/conf.d/magento.conf
    2. Add the following content, then save and exit.

      upstream fastcgi_backend {
        server  unix:/run/php/php8.3-fpm.sock;
      }
      server {
        listen 80;
        server_name ip;
        set $MAGE_ROOT /var/www/html/magento;
        include /var/www/html/magento/nginx.conf.sample;
      }
      
    3. Verify the NGINX syntax.

      nginx -t
    4. Restart NGINX.

      sudo systemctl restart nginx

Visit the Magento 2 website

  1. Open http://<Public IP address of your ECS instance> in a browser to view the default home page.

    image

  2. Open http://<Public IP address of the ECS instance>/admin_46i**** and log in with username admin and password admin***.

    image

FAQ

Q1: What do I do if I cannot download the Magento2 software package?

Update the image repository to resolve this issue.

image

  1. View the current image repository.

    composer config -l -g

    image

  2. Switch to an Alibaba Cloud mirror.

    sudo composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

Q2: What operations can I perform on a domain name?

To use a custom domain for your website, purchase a domain name. If your ECS instance resides in the Chinese mainland, apply for an ICP filing. Then resolve the domain name to the instance's public IP address.

  • Purchase a domain name.

    A domain name gives users an easy-to-remember address instead of an IP address.

    You can register a domain name on Alibaba Cloud.

  • Apply for an ICP filing for the domain name.

    An ICP filing is mandatory for any domain name that resolves to a server in a Chinese mainland region. The website cannot be publicly accessible until it receives an ICP filing number.

  • Resolve the domain name.

    Resolve the domain name to the ECS instance's IP address with Alibaba Cloud DNS so users can access your website by domain name. See Get started.

References