In this guide, we will show you how to Install Magento 2 using Composer on Ubuntu. Whether you are setting up a new store or a development environment, learning to Install Magento 2 correctly with OpenSearch is essential for peak performance
Table of Contents
What is Magento?
Magento is a powerful open-source e-commerce platform written in PHP, that helps programmers create eCommerce websites to sell online.
It is known for its powerful features, scalability, and flexibility, offering different editions (including a free one) for businesses of all sizes, from small ventures to large enterprises.
In another word, Magento is one of the well-known eCommerce websites where retailers can build an online store and deliver their customers online shopping experiences.
What is Magento 2 ?
Magento 2 is the latest major version of the Magento e-commerce platform, launched in 2015 as a complete overhaul of the original Magento (now referred to as Magento 1). It’s more modern, faster, scalable, and user-friendly than its predecessor.
Why Install Magento 2 on Ubuntu?
When you Install Magento 2 on an Ubuntu server, you are choosing a high-performance environment. It is the most stable way to Install Magento 2 for production use. By using Composer to Install Magento 2, you ensure that all dependencies and OpenSearch requirements are met correctly.
Installation Requirements For Magento 2:
Operating systems (Linux x86-64)
- Distributions of Linux, including RedHat Enterprise Linux (RHEL), CentOS, Ubuntu, Debian, etc.
Memory requirement
- Magento 2 requires 4 GB or higher RAM.
Composer
- Composer 2.2.x
Web servers
- Apache 2.4
- Nginx 1.x
Database
- MySQL 8.0
- MariaDB 10.6
PHP
Magento 2 supports PHP 8.1 or PHP 8.3
Search Engine
- opensearch-2.x
- openjdk-17-jdk
What We’re Going To Use:
- OS: Ubuntu 24.04 LTS
- SERVER: Nginx 1.18
- RAM: 8 GB
- CPU: 2
- PHP: 8.3
- MY SQL: 8.0
- Composer: 2.8.12
- OpenSearch: 2.x
Steps for Install Magneto 2 on Ubuntu 22.04 LTS using composer:
Step 1: Update Operating System
Perform updates to keep your Ubuntu 22.04 LTS OS current. It ensures your system is equipped with the latest package versions.
sudo apt update && sudo apt upgrade -yStep 2: Install Nginx web server
- Install Nginx by running the following command:
apt install nginx- Once the installation is complete, start Nginx with this command:
systemctl start nginx- Ensure Nginx starts automatically on boot with the following command:
systemctl enable nginxNginx is now installed, running, and configured to start on boot.
Step 3: Install PHP and PHP extensions
Ensure you have the right PHP version and extensions to Intall Magento 2
- Install PHP 8.3 with necessary extensions using the following commands:
apt-get update && apt upgrade
sudo dpkg -l | grep php | tee packages.txt
apt install apt-transport-https zip unzip
add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.3 php8.3-cli php8.3-{bz2,curl,mbstring,intl,gd,zip,mysql,soap,fpm,xml,bcmath,dev} - Verify if PHP is installed.
php -v
Step 4: Update php.ini file
Customize your PHP configuration for Magento 2 by following these steps:
- Find the PHP configuration file by running:
php --ini | grep "Loaded Configuration File"
- You’ll get an output like:
Loaded Configuration File: /etc/php/8.3/cli/php.ini
- Open the php.ini file for editing:
nano /etc/php/8.3/cli/php.ini
- Modify the following settings in the php.ini file:
- Set
file_uploadsto On - Set
allow_url_fopento On - Set
short_open_tagto On - Set
upload_max_filesizeto 128M - Increase
max_execution_timeto 3600
Save the changes to the php.ini file.
To apply the configuration changes, restart Nginx:
systemctl restart nginx
Now, your PHP configuration is optimized to meet the requirements of Magento 2
Step 5: Install MySQL 8 and create database
Set up MySQL 8 and create a database for Magento 2.4.6 by following these steps:
- Install MySQL with this command:
apt install mysql-server
- Start the MySQL database server and enable it to start automatically on boot:
systemctl start mysql
systemctl enable mysql
- After installing and starting MySQL, execute command mysql_secure_installation to improve the security of your MySQL installation.
4. After installing and starting MySQL, access the MySQL prompt by executing following command:
mysql -u root -p5. Within the MySQL prompt, execute the following commands to create a database, database user, and grant all privileges to the user.
mysql> CREATE DATABASE magento2;
mysql> CREATE USER 'admin'@'localhost' IDENTIFIED BY 'm12021885R@#3';
mysql> GRANT ALL ON magento2.* TO 'admin'@'localhost';
mysql> GRANT ALL ON *.* TO 'admin'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> EXIT
Step 6: Installing OpenSearch:
Configure Magento 2 OpenSearch as the catalog search engine for Magento 2.4.8 with these steps:
- Install the necessary dependencies:
sudo apt -y install curl lsb-release gnupg2 ca-certificates sudo apt install -y openjdk-17-jdk - Import the GPG key required to sign OpenSearch packages:
sudo curl -fsSL https://artifacts.opensearch.org/publickeys/opensearch.pgp | gpg --dearmor -o /etc/apt/trusted.gpg.d/opensearch.gpg3. Add the OpenSearch repository to your sources list.
sudo echo "deb https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable main" | tee /etc/apt/sources.list.d/opensearch-2.x.list4. Update the apt package manager and install OpenSearch:
sudo apt update -y5. To set an initial admin password for OpenSearch during installation, use the following command. Replace “Y0ur@SecurP4assword” with a secure password of your choice:
sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=Y0ur@SecurP4assword apt install opensearch6. Once installed, you need to adjust the configuration file to match your Magento store requirements. Open the configuration file and Modify these settings based on your needs:
nano /etc/opensearch/opensearch.ymlcluster.name: magento2
network.host: localhost
http.port: 9200
plugins.security.disabled: true # Add in last of this page
7. After making the necessary adjustments, reload the systemd daemon to apply changes:
systemctl daemon-reload
systemctl restart opensearch
systemctl status opensearch curl -X GET "localhost:9200/"
If OpenSeach is working correctly, you’ll receive an output like this:
root@magento2:/var/www/html/magento2# curl -X GET "localhost:9200/"
{
"name" : "magento2",
"cluster_name" : "linuxgkworld",
"cluster_uuid" : "uktxy7OtTxahO2Pu-HEeoQ",
"version" : {
"distribution" : "opensearch",
"number" : "2.19.4",
"build_type" : "deb",
"build_hash" : "e2e89961c9a327daf514a7ce1320a6189bfd08cd",
"build_date" : "2025-11-01T02:36:57.252966817Z",
"build_snapshot" : false,
"lucene_version" : "9.12.3",
"minimum_wire_compatibility_version" : "7.10.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "The OpenSearch Project: https://opensearch.org/"
}
Step 7: Install Composer
- Download Composer using this command:
sudo curl -sS https://getcomposer.org/installer | php
- Move the Composer file to the
/usr/local/binpath:
sudo mv composer.phar /usr/local/bin/composer
- Grant execute permission to Composer:
sudo chmod +x /usr/local/bin/composer
- Verify the Composer version to confirm the installation:
sudo composer --version
- You should see output similar to:
Composer version 2.5.4 2023-02-15 13:10:06You can also visit compose office site https://getcomposer.org/ to download composer.
Step 8: Download and Install Magento 2 packages
Installing Magento using the Marketplace by creating an access key is recommended.
Generate Access keys by navigating to: My profile > Marketplace > My products > Access Keys.
Download Magento 2 latest data with the following command:
sudo composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /var/www/html/magento2When prompted, provide your Public Key as the username and Private Key as the password.
Navigate to the Magento directory:
cd /var/www/html/magento2
- Set appropriate permissions for cache and static content folders:
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
- Change the ownership of the Magento directory to the webserver user and adjust permissions:
chown -R www-data:www-data /var/www/html/magento2
chmod -R 755 /var/www/html/magento2
- Install Magento using the composer command. Customize the parameters according to your environment:
php8.3 bin/magento setup:install \
--base-url=http://linuxgkworld.com \
--db-host=localhost \
--db-name=magento2 \
--db-user= admin \
--db-password=m12021885R@#3 \
--admin-firstname=Admin \
--admin-lastname=User \
--admin-email=admin@example.com \
--admin-user=admin \
--admin-password=m12021885R@#4 \
--language=en_US \
--currency=USD \
--timezone=Asia/Kolkata \
--use-rewrites=1 \
--search-engine=opensearch\
--opensearch-host=localhost \
--opensearch-port=9200 \
--opensearch-timeout=15 \
--opensearch-index-prefix=magento2
- You will receive the admin link for your Magento site after successful installation.
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_o07lew
Nothing to import.Step 9: Configure Nginx Web Server for Magento 2.4.6
- Navigate to the Nginx configuration directory:
cd /etc/nginx/sites-available
- Create a configuration file for your Magento installation:
sudo nano /etc/nginx/sites-available/magneto2.conf- Add the following content to the file, customizing it as needed (replace
your-domain.comwith your actual domain):
upstream fastcgi_backend { server unix:/run/php/php8.3-fpm.sock; } server { listen 80; server_name your-domain.com www.your-domain.com; set $MAGE_ROOT /var/www/html/magento2;
access_log /var/log/nginx/magento-access.log;
error_log /var/log/nginx/magento-error.log;
include /var/www/html/magento2/nginx.conf.sample;
}
Save the file and exit the text editor.
Check syntax error and Restart the Nginx web server to apply the configuration changes:
ln -s /etc/nginx/sites-available/magneto2.conf /etc/nginx/sites-enabled
nginx -t
systemctl restart nginxStep 10: Access your Magento 2 Application
Now that your Magento 2 installation is set up, access it through your web browser:
- Open your preferred web browser.
- In the address bar, type your domain, e.g.,
http://your-domain.cos
Conclusion
Now that you know how to Install Magento 2 using Composer, you can begin your e-commerce journey. This process to Install Magento 2 is the standard for professional developers worldwide.
1 thought on “How to Install Magento 2 on Ubuntu with OpenSearch: The Best Ultimate Guide”
Pingback: How to Install Magento 2 Using Composer in Ubuntu with nginx - LinuxGKTech