×



















    Get a Free Consultation

    Search for:

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

    Last Updated | December 6, 2023

    Introducing our comprehensive guide for 2023: “Step-by-Step Guide to Install Magento 2 With Composer.” In this tutorial, we’ll walk you through the latest techniques and best practices to effortlessly install Magento 2 using Composer. Whether you’re a seasoned developer or new to the world of e-commerce, this guide will provide you with the knowledge and step-by-step instructions needed to set up Magento 2 with confidence and precision. Stay ahead in the e-commerce game with the most up-to-date installation process for Magento 2.

    What is Composer?

    An instrument for reliance on the board inside Magento 2 that smoothes out the interaction. The composer plays a key role in gathering components and product editions. 

    Installing Magento 2 with Composer gives a more smoothed-out and bother-free insight. In Magento 2, Composer is used to manage the installation and update of the core software, extensions, and libraries.

    Magento 2 install extension with composer has significantly simplified the process of managing dependencies and integrating third-party modules into Magento 2.

    how to start Magento 2 with composer beginning from Magento adaptation 2.4.2 onwards, the command line is the default (and only) strategy for introducing Magento. Keeping in mind that you could download an archive of the Magento version that you need to introduce, this strategy isn’t exactly prescribed and you should use Composer to download Magento instead.

    Magento 2 with Composer Advantages

    Installing Magento 2 with Composer offers several advantages, contributing to a more efficient and manageable development process. Here are some key advantages:

    Dependency Management:

    One of the essential motivations for involving Composer for Magento 2 installation is its dependency management abilities. Magento 2 depends on different outsider libraries and bundles, and dealing with these conditions can be complicated. Composer is a powerful dependency manager for PHP, and it allows Magento 2 to manage its dependencies seamlessly. This ensures that the correct versions of required libraries and modules are installed.

    Easy Updates:

    Installing Magento 2 with composer simplifies the process of updating Magento 2 and its dependencies. By running a single command (composer update), you can easily update Magento to the latest version or update specific modules.

    Version Constraints:

    Magento 2 applies version constraints to set the acceptable versions of dependencies. This helps ensure compatibility and solidness and makes it easier to manage your project under version control systems like Git.

    You can specify version constraints in the composer.json file. For example:

    “require”: {
    “vendor/package-name”: “^1.0”
    }

    Module Installation:

    Installing Magento 2 modules (extensions) becomes straightforward with Composer. You can use the composer require command to add new modules to your project, and Composer will handle the installation and version resolution.

    Centralized Package Repository:

    Magento 2 uses the Composer package manager to connect to the Magento Composer repository. This centralized repository ensures that you have access to official Magento packages, making it easy to install and update the core software.

    Efficient Deployment:

    For deployment, you can use the composer install command to install the exact versions of dependencies as specified in the composer.lock file. This ensures that your production environment matches your development environment precisely.

    General Requirements and Steps to Set up a Magento 2 Store

    Running a Magento 2 store requires meeting certain system requirements and performing specific setup steps. Here are the general requirements and steps to set up a Magento 2 store:

    System Requirements:

    Web Server:

    Apache 2.4 or Nginx 1.x

    Database:

    MySQL 8.0 or MariaDB 10.4

    PHP:

    PHP 7.4 | 8.1 (Magento 2.4.x) or PHP 7.3 (Magento 2.3.x)

    Required PHP extensions: bc-math, ctype, curl, dom, gd, intl, mbstring, openssl, pdo_mysql, simplexml, soap, xsl, zip, json, iconv

    Elasticsearch (Optional, but recommended for catalog search):

    Elasticsearch 7.x

    Composer:

    Composer is required for installing and managing Magento 2 and its dependencies.

    Server Configuration:

    PHP memory_limit: 2 GB or more

    Web server rewrites: Apache mod_rewrite or Nginx configuration for rewrites

    Operating System:

    Magento 2 is compatible with Linux distributions (specifically Ubuntu, CentOS, and Red Hat Enterprise Linux).

    Authentication Keys

    To install or update Magento 2 using Composer, you need to authenticate your Composer installation with your Magento Marketplace account. This involves obtaining and using authentication keys provided by Magento.

    To get the validation keys, create an account on the Magento Marketplace. Explore the “Access Keys” section, and generate a pair of public and private keys.

    You can create the auth.json file in the Magento 2 root directory.
    An auth.json file can look like this:

    {
    “github-oauth”: {
    “github.com”: “<your GitHub key>”
    }
    ,”http-basic”: {
    “repo.magento.com”: {
    “username”: “<your public Magento Connect key>”,
    “password”: “<your private Magento Connect key>”
    }
    }
    }

    Web Server File System Owner

    Before attempting to download the Magento it is recommended to confirm the folder/file owner

    such as public_html or var/www/html. It guarantees the web server can get to and modify the files when required. Owner and group of a directory can be check ls -ld /path/to/folder

    In order to create a new user under www-data group run the following command

    useradd -g www-data [username]

    ### set the password for the user ###

    sudo passwd [username]

    For updating/chossing the files owner run the following command

    sudo chown -R :www-data . &&

    sudo chmod u+x bin/magento &&

    sudo chown -R [username]:www-data . &&

    sudo usermod -a -G www-data [username]

    Replace [username] with your user name e.g magento.

    Install Magento 2 with Composer

    To install Magento 2 using Composer, you can follow these steps. This assumes you have already set up your server environment with the necessary prerequisites like a web server, PHP, MySQL, and Composer itself.

    Magento 2 install with composer from command line

    1. Get Composer

    Make sure you have Composer installed on your system. You can download and install Composer by following the instructions on the Composer website.

    To install Composer on your server follow these commands:

    • curl -sS https://getcomposer.org/installer | php
    • mv composer.phar /use/local/bin

    2. Magento 2 Composer Package

    Navigate to /var/www/html or public_html folder and run the following Composer command to create a new Magento 2 project:

    Adobe Commerce (Enterprise)

    composer create-project –repository-url=https://repo.magento.com/ magento/project-enterprise-edition <MAGENTO_ROOT_FOLDER>

    Magento Open Source

    composer create-project –repository-url=https://repo.magento.com/ magento/project-community-edition <MAGENTO_ROOT_FOLDER>

    3. Authenticate with Magento Marketplace

    If you haven’t already done so, you need to authenticate Composer with your Magento Marketplace account. This step is essential for accessing Magento 2 packages. You’ll need your Magento Marketplace public and private keys. Run the following command and follow the prompts:

    composer auth –http-basic.repo.magento.com <public-key> <private-key>

    Replace <public-key> and <private-key> with your Magento Marketplace authentication keys.

    4. Set File Permissions

    You should set the correct permissions for the whole Magento 2 installation directory by running the below command:

    find . -type f -exec chmod 644 {} \;            

    find . -type d -exec chmod 755 {} \;        

    chmod -Rf 777 var

    chmod -Rf 777 pub/static

    chmod -Rf 777 pub/media

    chmod 777 ./app/etc

    chmod 644 ./app/etc/*.xml

    chmod -Rf 775 bin

     

    5. Set the Database

    Create a MySQL database for Magento 2 and a database user with the necessary privileges.

    echo “CREATE DATABASE magento2” | mysql -u [mysqluser] -p

    6. Install Magento 2 

    Run the Magento 2 installation command:

    php bin/magento setup:install

    –base-url=”http://yoururl.com/”

    –db-host=”localhost”

    –db-name=”dbname”

    –db-user=”dbuser”

    –db-password=”dbpass”

    –admin-firstname=”admin”

    –admin-lastname=”adminx”

    –admin-email=”[email protected]

    –admin-user=”admin”

    –admin-password=”admin123

    –language=”en_US”

    –currency=”USD”

    –timezone=”America/Chicago”

    –use-rewrites=”1″

    –backend-frontname=”admin”

    Note: This command contains dummy data please replace the placeholders with your own data and preferred configurations.

    Once finished, it will inform you of the installation’s completion.

     

    7. Enable Developer Mode (Optional)

    For development, you can enable developer mode:

    Command: bin/magento deploy:mode:set developer

     

    Install the latest Magento 2 via composer with sample data and elasticsearch

    To set elasticsearch configuration assuming it’s already been installed on the server, you can add the following attributes in the above command php bin/magento setup:install.

     

    –search-engine=elasticsearch7 

    –elasticsearch-host=127.0.0.1

    –elasticsearch-port=9200

     

    Install magento 2 with sample data via composer the installations/uninstallations should be possible with following commands ought to be executed in magento root.

     

    bin/magento sampledata:deploy

    bin/magento sampledata:remove

     

    After running the command, you can flush the cache and recompile the site using these commands:

     

    php bin/magento cache:flush

    php bin/magento setup:di:compile 

     

    After the installation, you should access your new Magento 2 store using the configured base URL.

     

    Conclusion

    Congrats on effectively introducing Magento 2 utilizing Composer! With this proficient, secure, and effectively updatable establishment strategy, you’re looking extraordinary so far in building your web-based store. 

    Installing Magento 2 via Composer is the recommended and efficient method, providing several advantages for managing dependencies, updates, and extensions.

    By exploiting these useful assets, you can guarantee that your Magento store is in top shape and prepared to succeed.

     

    FAQs

    Q: How to uninstall the Magento 2 module with composer?

    1. Disable the module run bin/magento module:disable vendor/module-name. Format would be e.g. Folio3/PaymentRestrictions.
    2. Run composer remove vendor/module-name this command will remove the module name from composer.json.
    3. Deploying the site run php bin/magento setup:upgrade && php bin/magento setup:di:compile && php bin/magento setup:static-content:deploy &&  php bin/magento cache:clean

    And this is all. The composer removes the extension files smoothly.

    Q: How to install the module with composer Magento 2?

    Magento 2 install module with composer walkthrough following are the steps.

    1. Run command composer require vendor/package-name Replace vendor/package-name with the actual Composer package name of the module. For the older version use composer require package_name:version.
    2. Enable the module run bin/magento module:enable Vendor_Module
    3. Deploying the site run php bin/magento setup:upgrade && php bin/magento setup:di:compile && php bin/magento setup:static-content:deploy &&  php bin/magento cache:clean

    If the extension is from the Magento Marketplace, make sure you have authenticated Composer with your Magento Marketplace account by using public and private keys.

    Q: what version of Composer is compatible with Magento 2?

    Magento supports composer 2.0 or later for all the Magento 2 variants except 2.4.2 p2 and 2.4.3 p3 which can used under composer 1. The latest Magento version can accommodate composer  2.4.7-beta2.

     

    For Magento 2.4.4-p2, 2.4.4-p1 & 2.4.4 composer 2.1 is supported.

    For Magento 2.4.4-p3 to 2.4.6-p3 composer 2.2 is supported.

     

    To check the Composer version on your system, you can run: composer –version  

    For further information please visit Adobe System Requirement

     

    Q: How do I install Magento 2?

    Follow the step instructions below to install Magento 2

    • Setup the server and satisfy the Magento requirements
    • Install Composer
    • Download Magento
    • Set the authentication keys
    • Set the permissions
    • Create MYSQL/MariaDB database
    • Install Magento 2

    folio-social-logo
    About

    Passionate about creating seamless online shopping experiences and helping businesses thrive in the digital marketplace. With [6] years of experience in e-commerce development, I've had the privilege of working on a variety of projects, from small startups to established brands. Feel free to connect with me, and let's explore how we can work together to boost your online business