This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Introducing DigitalOceans General Purpose & CPU Optimized Servers on Cloudways Flexible. Learn More

Step-by-Step Guide to Install Magento 2 With Composer (2025)

Updated on April 3, 2025

10 Min Read
install Magento 2 via Composer

Key Takeaways:

  • Composer is the preferred method for installing Magento 2, simplifying dependency management and updates.
  • Cloudways provides a one-click Magento 2 installation, ideal for users wanting a quick and easy setup.
  • Both methods require meeting certain prerequisites, and troubleshooting tips are available for common installation issues.

Installing Magento 2 manually can be tedious, especially when dealing with dependencies, libraries, and version compatibility. Even for experienced developers, keeping everything in sync can be challenging.

Using Composer simplifies the process by managing dependencies automatically, reducing errors, and making updates more efficient. In Magento 2.4 and later, Composer is required for installation, making it essential to understand how it works.

This guide will walk through two methods for installing Magento 2 with Composer:”

  • Install Magento 2 via Composer
  • Install Magento 2 on Cloudways

Let’s get started…

What Is Composer?

Composer is an open-source dependency manager for PHP that helps developers manage libraries and packages efficiently. Instead of manually handling dependencies, Composer automates the process, ensuring compatibility and easy updates.

It works by using a project-level JSON file to define required packages. The composer then finds and installs the best versions while considering system requirements and nested dependencies.

Most PHP libraries are available through Packagist, the official repository. While many packages are free, a premium option allows private package hosting for closed-source projects.

All and all, by handling dependencies efficiently, Composer helps keep PHP applications organized and up to date.

Advantages of Installing Magento 2 via Composer

Using Composer to install Magento 2 simplifies dependency management and ensures a more structured setup. Here’s why it’s beneficial:

  • Efficient Dependency Management: Composer allows Magento 2 to reuse third-party libraries without bundling them into its core files, keeping the codebase clean.
  • Simplified Extension Handling: It reduces conflicts by following a component-based architecture with robust dependency management. Learn more about Magento extensions.
  • Better Compatibility: Composer aligns with PHP-FIG (Framework Interoperability Group) standards, improving code consistency across different PHP frameworks.
  • Easier Updates & Customization: Magento 2 can be repackaged with other components, making it more flexible for development and deployment.
  • Optimized for Production: Composer ensures Magento 2 is structured properly for production environments, streamlining deployment and performance.

If you’re ready to install Magento 2 using Composer, follow this step-by-step guide for a smooth setup.

Requirements for Running Magento 2 Store

Before proceeding with the Magento 2 installation using Composer, ensure you meet the basic requirements for running a Magento 2 store:

  • Server: Linux-based OS (Ubuntu, CentOS, Debian)
  • Web Server: Apache 2.4 or Nginx 1.8+
  • PHP: Version 8.1 or 8.2 with required extensions
  • Database: MySQL 8.0 or MariaDB 10.4+
  • Composer: Version 2.x for managing dependencies
  • Memory: At least 2GB RAM (4GB+ recommended)
  • Storage: SSD for better performance
  • SSL Certificate: Required for secure transactions
  • Magento Authentication Keys: Obtain authentication keys from the Magento Composer Repository. You will need these credentials during installation.
  • Server Access: Ensure you have SSH access to your server and the required permissions to install and configure Magento 2.

Related post: How to Fix SSH Connection Refused Error: A Detailed Guide

Launching Magento 2 on Cloudways Is as Easy as 1-2-3

Cloudways Platform is built for ecommerce store owners who want to focus on business growth without wasting their time on technicalities.

How to Install Magento 2 via Composer?

Installing Magento can be complex and time-consuming, but Composer can simplify the process. That said, we will now cover the key details for installing Magento successfully using Composer.

Step 1: Install Magento Composer Using Command Line or a Download Link

Composer is a popular dependency manager for PHP that simplifies installing and managing packages for PHP applications. It can be installed using the command line or a download link.

Here’s how:

1. Installing Composer using the command line:

a) Download the Composer installation file by running the following command in your terminal:

curl -sS https://getcomposer.org/installer | php

b) This will download the Composer installation file and save it as composer.phar in the current directory.

c) Move the composer.phar file to a directory in your $PATH variable. You can use the following command to move it to /usr/local/bin/:

$ sudo mv composer.phar /usr/local/bin/composer

d) Verify that Composer is installed by running the following command:

$ composer --version

2. Installing Composer using a download link:

a) Go to the official Composer website (https://getcomposer.org/download/) and download the Composer installation file for your operating system.

b) Once the download is complete, move the downloaded file to a directory in your $PATH variable. For example, if you’re using macOS, you can move the file to /usr/local/bin/.

c) Rename the file to composer (without the .phar extension) by running the following command:

sudo mv composer.phar /usr/local/bin/composer

d) Verify that Composer is installed by running the following command:

$ composer --version

That’s it! You have successfully installed Composer using either the command line or a download link. Now, you can use Composer to manage dependencies for your PHP applications.

Please Note: If you encounter any technical issues, feel free to ask in the comments. For more information, please refer to Magento’s official documentation.

Step 2: Login As a File System Owner

1. Before installing Magento 2, you need to access the directory where you want to install it, such as public_html or var/www/html/magento2. If you are logged into the Magento server, make sure that the file system owner of the server directory is a user with “write” permission to the Magento file system.

permission to the Magento file system

2. Add <magento_root>/bin to your system PATH to run Magento commands from any directory.

export PATH=$PATH:/var/www/html/magento2/bin

Optionally, you can run the commands in the following ways:

cd <magento_root>/bin and run them as ./magento <command name>
<magento_root>/bin/magento <command name>
<magento_root> is a subdirectory of your web server docroot.

Note: Please follow the instructions further to download the Magento Meta package.

Step 3: Download Magento

You can download the Magento 2 version directly from its official website.

OR

Run a command using composer to download a specific Magento 2 version.

Command:

composer create-project --repository-url=https://repo.magento.com/
magento/project-community-edition <install-directory-name>

Magento Open Source

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition:2.4.6 .

Adobe Commerce (Enterprise)

composer create-project --repository-url=https://repo.magento.com/
magento/project-enterprise-edition:2.4.6

In magento installation, you can specify the specific version of Magento (2.0, 2.1, 2.2.1, 2.2.2, 2.2.3, 2.2.4, 2.2.5, 2.2.6, 2.3, 2.4) using the above command.

Note: To install Magento 2 using composer in the current directory (e.g., public_html), remember to add the (.) dot at the end.

During this process, before downloading Magento, you will be asked to insert your repo.magento.com username and password.

⚠️ Important: You must generate authentication keys:

For the repo.magento.com username and password, log in to Magento Marketplace and select My Account from the top-right corner. Now click Access Keys and Generate your new SECURE KEYS.

  • Public Key: Is your username
  • Private Key: Is your password

After inserting your repo.magento.com username and password, it will ask for store credentials. Type “Yes.

Then Magento 2 will now start downloading on your server.

Create project repository

Step 4: Set Permission to Install Magento 2.4

To install Magento 2, you must set proper permissions for your Magento 2 Store. Magento recommends a set of permissions that we must apply.

a ) The owner must have full access to files.

b ) The web server must have write permission for var, app/etc, and pub directory.

c ) Execute permission of bin/magento.

Certain commands for permissions are required to be executed at this stage:

Command:

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find var generated vendor pub/static pub/media app/etc -type f -exec chmod u+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod u+w {} +
chmod u+x bin/magento
chmod 644 ./app/etc/*.xml
chmod -Rf 775 bin

Step 5: Create a Database for Magento installation

Create an empty database with MySQL/MariaDB

Command:

mysql -u [mysqluser] -p -e "CREATE DATABASE magento2;"

Step 6: Install Magento 2.4

Now, the install Magento command needs to be executed

Command:

php bin/magento setup:install --base-url="http://phpstack-739336-2511019.cloudwaysapps.com/"
--db-host="167.99.205.158"
--db-name="magento2"
--db-user="yrzhqayjyq"
--db-password="VA2r8RdxAe"
--admin-firstname="Admin"
--admin-lastname="Admin"
--admin-email="[email protected]"
--admin-user="admin"
--admin-password="Testing123%567"
--use-rewrites="1"
--backend-frontname="admin"
--db-prefix=mage_

The above command ensures the following:

  • Base URL: http://yoururl/cloudways.com” is set as your application URL.
  • Database Host (db-host): The hostname or IP address of your server.
  • Database Name (db-name): The name of your Magento database.
  • Database User (db-user): The username for your database.
  • Database Password (db-password): The password for your database.
  • Admin Credentials: You can customize the admin’s first name, last name, and other parameters as needed.

Note: This command is executed with dummy data. You need to fill in this information based on your application information.

Magento installation complete

You have now successfully installed Magento 2 using Composer. Let’s get started with configurations.

Now, you just gotta run the readiness check and start your Magento store.

installation steps

After installing Magento, use the commands below to optimize and secure your store:

Set Production Mode (for better performance):

php bin/magento deploy:mode:set production

Enable Cron Jobs (required for Magento tasks like indexing):

php bin/magento cron:install

Reindex & Clear Cache (to avoid frontend/backend issues):

php bin/magento indexer:reindex
php bin/magento cache:flush

7. Preview Your Magento 2 Store

After a successful Magento 2 installation on your Cloudways server using composer, this is how your Magento 2 Frontend and Backend should look like.

Frontend

Luma Homepage

Backend

Magento login credentials

Note: If you are installing Magento 2 using Composer and want to configure Varnish on it, then follow our how-to setup Magento 2 with Varnish tutorial.

How to Install Magento 2 Using Cloudways Platform (Super Easy)

Installing Magento 2 can be a time-consuming process, especially for store owners who want to focus on growing their business rather than dealing with complex technical setups. That’s where Cloudways comes in.

At Cloudways, we simplify Magento 2 installation with an intuitive platform that eliminates the need for manual server configurations. Our platform provides all the necessary server requirements, ensuring a seamless setup and optimal performance from the start.

Tip: You can request a live Demo to test out the performance of Magento on Cloudways.

Now that we’ve gotten that out of the way, let’s see how you can install Magento 2 using the Cloudways Platform in a few simple steps.

Step 1: Signup/Login to Your Account

  • Sign up for Cloudways if you don’t have an account yet, or log in if you’re already a Cloudways user.

Cloudways signup page

Step 2: Select Magento Application

  • After logging in, create a server and select the version to install Magento from the Application dropdown. Also, provide details for your server and application name.

Select Application:

Select your application

  • Fill in the remaining fields to install Magento.

Deploy Application servers

Step 3: Choose Cloud Providers

  • Select the Cloud Provider of your choice.

Select cloud provider

Step 4: Select Server Size & Bandwidth

  • Select Server Size & Bandwidth according to your requirements.

Select the server size

Step 5: Define Server Storage

  • Now, select your Server Storage. You can always scale up whenever required.

Storage sizes

Step 6: Select Server Location

  • Select your server Location by keeping the latency factor in mind.

Server Location

  • Now click on the Launch Server button from the bottom of the page and wait for your server preparation.

Launch button

  • Go to your Server and check the server and application details
  • Once the server is ready, go to Application Management from the top menu bar and log in to your Magento 2 store using the Access Details.

Server Details:

Master credentials

Application Details:

Access Details

Check Your Application:
Advanced reporting

Done with installing Magento 2 With Composer?

Take your Magento 2 store to the next level with Cloudways’ Best Managed Magento Hosting. Get fast, scalable, and secure hosting managed by experts 24/7.

Install Magento 2 With Composer – Troubleshooting Tips

Sometimes, things don’t go as planned during installation. Here are some common issues you may encounter during the installation process and some possible solutions:

1. “Fatal error: Allowed memory size exhausted” message:

This error can occur when the PHP memory limit is set too low. You can try increasing the memory limit in your php.ini file by adding the following line:

memory_limit = 2G

If that doesn’t work, you can also try running the following command in your terminal:

php -d memory_limit=-1 /usr/local/bin/composer install

2. “Class ‘Locale’ not found” message:

This error can occur when the PHP extension for the ‘intl’ package is not installed. You can install the ‘intl’ package by running the following command in your terminal:

sudo apt-get install php-intl

3. “The requested PHP extension ext-iconv * is missing from your system” message:

This error can occur when the PHP extension for the ‘iconv’ package is not installed. You can install the ‘iconv’ package by running the following command in your terminal:

sudo apt-get install php-iconv

4. “The requested PHP extension ext-mbstring * is missing from your system” message:

This error can occur when the PHP extension for the ‘mbstring’ package is not installed. You can install the ‘mbstring’ package by running the following command in your terminal:

sudo apt-get install php-mbstring

5. “Could not open input file: composer.phar” message:

This error can occur when the ‘composer.phar’ file is not located in the correct directory. Make sure you are running the command from the directory where the ‘composer.phar’ file is located. If the file is not in that directory, you can download it from the Composer website and move it to the correct directory.

Final Words

Congratulations on successfully installing Magento 2 using Composer! Now that you have your Magento 2 store set up, you can begin customizing it and adding products to expand your business online.

If you’re looking for a hassle-free way to host and manage your Magento store, Cloudways offers Magento managed hosting with built-in performance and security features. That way, you can focus on growing your business without getting caught up in server management.

If you have any questions or think we missing something, let us know in the comments below.

Install Magento 2 FAQs

Q: How do I install Magento 2?

To install Magento 2, follow these 5 steps

  • Step 1: Setup the server and fulfill the Magento requirements
  • Step 2: Install Composer
  • Step 3: Download Magento 2
  • Step 4: Set Permission to Install Magento 2
  • Step 5: Create a Database for Magento installation
  • Step 6: Install Magento 2

Q: What is the command to install Magento 2?

Once Magento 2 to is downloaded, run this command to install Magento:

php bin/magento setup:install

Q: What is the role of the Composer in Magento 2?

Magento 2 uses a Composer as a dependency manager to maintain and upgrade the Magento components. Composer is linked to Magento code for developing any Magento component the key part is it reads the Composer.json file in Magento’s root directory to download the dependencies listed in the file.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Jyotishna Kumari

Jyotishina is the Magento Community Expert at Cloudways and has 4 years of experience in web development. She has worked on e-commerce sites since the turn of the millennium and was working with Magento before version 1 was released. She loves to travel and explore new ideas whenever she finds time. Get in touch with her at [email protected].

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour