In this guide, you will learn how to Install Magento 2 using Composer on Ubuntu. Whether you are a developer or a store owner, knowing the correct way to Install Magento 2 with Nginx is the first step toward building a high-performance e-commerce site.
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.
Installation Requirements For Magento 2:
The Followings are the requirements to install Magento 2 on ubuntu.
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
Elasticsearch
- Elasticsearch 7.17 or later version
What We’re Going To Use:
- OS: Ubuntu 22.04 LTS
- SERVER: Nginx 1.18
- RAM: 8 GB
- CPU: 2
- PHP: 8.3
- MY SQL: 8.0
- Composer: 2.8.12
- Elasticsearch: 9.1.5
Steps for Magento 2 Installation 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 for 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.
This program enables you to improve the security of your MySQL installation in the following ways:
You can set a password for
rootaccounts.You can remove
rootaccounts that are accessible from outside the local host.You can remove anonymous-user accounts.
You can remove the
testdatabase (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start withtest_.
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 magentodb;
mysql> CREATE USER 'magentouser'@'localhost' IDENTIFIED BY 'MyPassword';
mysql> GRANT ALL ON magentodb.* TO 'magentouser'@'localhost';
mysql> GRANT ALL ON *.* TO 'magentouser'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> EXIT
Step 6: Installing Elasticsearch:
Configure Magento 2 Elasticsearch as the catalog search engine for Magento 2.4.6 with these steps:
- Import the Elasticsearch GPG key:
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | gpg --dearmor | sudo tee /usr/share/keyrings/elasticsearch-keyring.gpg > /dev/null- Add the Elasticsearch repository:
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/9.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-9.x.list
- Update the apt package manager and install Elasticsearch:
apt update && apt install elasticsearch- Start and enable the Elasticsearch service:
sudo systemctl daemon-reload
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch- Open the elasticsearch.yml file for editing:
sudo nano /etc/elasticsearch/elasticsearch.yml
- Replace the following setting with ‘false’ to disable Magento security features and TLS:
# Disable security features
xpack.security.enabled: false
xpack.security.http.ssl.enabled = falseSave the changes to the elasticsearch.yml file.
Restart the Elasticsearch service to apply the configuration:
systemctl restart elasticsearch.service
- Verify that Elasticsearch runs correctly using the curl command:
curl -X GET "localhost:9200/"
- If Elasticsearch is working correctly, you’ll receive an output like this:
{
"name" : "magneto2-debain12-gk-node",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "IQjADEg8Qqy2NrT-q_TdaQ",
"version" : {
"number" : "9.1.3",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "0c781091a2f57de895a73a1391ff8426c0153c8d",
"build_date" : "2025-08-24T22:05:04.526302670Z",
"build_snapshot" : false,
"lucene_version" : "10.2.2",
"minimum_wire_compatibility_version" : "8.19.0",
"minimum_index_compatibility_version" : "8.0.0"
},
"tagline" : "You Know, for Search"
}
Step 7: Install Composer
- Download Composer using this command:
curl -sS https://getcomposer.org/installer | php
- Move the Composer file to the
/usr/local/binpath:
mv composer.phar /usr/local/bin/composer
- Grant execute permission to Composer:
chmod +x /usr/local/bin/composer
- Verify the Composer version to confirm the installation:
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: Install Magento 2
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:
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://test.example.com \
--db-host=localhost \
--db-name=magentodb \
--db-user=magentouser \
--db-password=MyPassword \
--admin-firstname=Admin \
--admin-lastname=User \
--admin-email=admin@example.com \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=Asia/Kolkata \
--use-rewrites=1 \
--search-engine=elasticsearch8 \
--elasticsearch-host=localhost \
--elasticsearch-port=9200 \
--elasticsearch-timeout=15 \
--elasticsearch-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/conf.d
- Create a configuration file for your Magento installation:
nano /etc/nginx/conf.d/magento2.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.
Restart the Nginx web server to apply the configuration changes:
systemctl restart nginx
Step 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.com
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.

3 thoughts on “Install Magento 2 on Ubuntu using composer with ElasticSearch: The Best Step-by-Step Guide”
Great Job
well done, its working smoothly please add commands also that you have use in video last min when you get error
Thanks for your comment. i will add those command here soon.