Deploy Magento 2, an open-source e-commerce platform, on an ECS instance running Ubuntu with NGINX, MySQL, OpenSearch, and Composer.
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
NoteMagento 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
-
Obtain your personal keys from Adobe Commerce.

-
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.
-
Port 22 is open in an inbound security group rule. See Add a security group rule.
-
Docker is installed on the ECS instance. See Install Docker.
-
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
-
Install the core PHP package and extensions.
-
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 -
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 -
Restart NGINX to apply the changes.
sudo systemctl restart nginx
-
-
Configure php.ini.
-
Open the php.ini files.
sudo vim /etc/php/8.3/fpm/php.ini sudo vim /etc/php/8.3/cli/php.ini -
Update the following settings, then save and close the files.
memory_limit = 2G max_execution_time = 1800 zlib.output_compression = On -
Restart PHP-FPM.
sudo systemctl restart php8.3-fpm
-
Step 2: Create a Magento2 database
-
Connect to MySQL.
mysql -u root -pEnter the MySQL root password when prompted.
-
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; -
Verify the database.
mysql -u magento -pNoteIf the MySQL monitor appears, the database is created. If an error occurs, re-run the preceding statements.
Step 3: Download and install OpenSearch
-
Before installing OpenSearch with Docker, complete the following tasks:
-
Disable memory paging and swapping to improve performance.
sudo swapoff -a -
Increase the memory map limit for OpenSearch.
-
Open sysctl.conf.
sudo vi /etc/sysctl.conf -
Add
vm.max_map_count=262144 -
Verify the configuration.
sudo sysctl -p cat /proc/sys/vm/max_map_count
-
-
-
Run OpenSearch in a Docker container.
-
Pull the OpenSearch image.
sudo docker pull opensearchproject/opensearch: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:latestNoteThis example disables SSL on the HTTP and Transport layers for testing by setting
plugins.security.disabledtotrue. -
Send a request to port 9200. The default credentials are admin/admin.
sudo curl -k http://localhost:9200 -ku admin:adminExpected 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/" }
-
-
List running containers and copy the OpenSearch container ID.
sudo docker container ls -
Configure NGINX as a proxy for OpenSearch.
-
Verify that /etc/nginx/nginx.conf contains
include /etc/nginx/conf.d/*.conf;.vi /etc/nginx/nginx.conf
-
Create the proxy configuration.
-
Create the following configuration file.
sudo vim /etc/nginx/conf.d/magento_es_auth.confserver { listen 8080; location /_cluster/health { proxy_pass http://localhost:9200/_cluster/health; } } -
Restart NGINX.
sudo service nginx restart -
Check whether the proxy works:
sudo curl -u admin:admin -i http://localhost:8080/_cluster/health?prettyExpected output:

-
-
Step 4: Download and install Composer
-
Install decompression tools.
Composer requires
unziporp7zipfor decompression.sudo apt-get install unzip sudo apt-get install p7zip-full -
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');" -
Move
composer.pharto a PATH directory for global access.sudo mv composer.phar /usr/local/bin/composer -
Verify the Composer version.
composer --version
Step 5: Download and install Magento2
-
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 -
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.

-
-
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 -
Install Magento 2.
Install Adobe Commerce from the command line. In this example,
db-hostis localhost, anddb-name,db-user, anddb-passwordare allmagento.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 -
After installation, output similar to the following is displayed.

The Magento Admin URI is the administrator backend URL, accessible after NGINX is configured. Example:
http://47.****.**.72/admin_46i****. -
Configure NGINX forwarding.
-
Create a Magento 2 configuration file.
sudo vim /etc/nginx/conf.d/magento.conf -
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; } -
Verify the NGINX syntax.
nginx -t -
Restart NGINX.
sudo systemctl restart nginx
-
Visit the Magento 2 website
-
Open
http://<Public IP address of your ECS instance>in a browser to view the default home page.
-
Open
http://<Public IP address of the ECS instance>/admin_46i****and log in with usernameadminand passwordadmin***.

