Among the various options available for installing Magento 2, installing it via Composer is perhaps the easiest and most efficient way of deploying this popular eCommerce solution. In Magento 2, Composer is considered a dependency management system that helps improve the various processes of installation. The turnaround time in the installation of Magento 2 offered through the use of Composer is relatively short and simple, especially with the Command-Line Interface (CLI) gaining so much prominence from Magento 2.4 and above. So, how to install Magento 2 using Composer?
This tutorial will walk through all the steps of installation in order to provide you with a solid and stress-free setup of Magento 2. It doesn’t matter if you’re a pro coder or have just started with Magento, following these steps will allow you to launch your website without any hassles.
Now, let’s begin!
Why Should Install Magento 2 via Composer?
Table of Contents
At this point, you might be wondering why installing Magento 2 using Composer is necessary rather than other methods. With years of experience in the eCommerce market, BSS Commerce believes the following key benefits are essential for your consideration:
1. Easy updates
One of the most significant advantages of using Composer to install Magento 2 is the ease of updates. This is because, with the use of a tool like Composer, there are no problems in updating every component of Magento 2. You simply pull in the versions of Magento and its dependencies that you need to work with only the most recent versions available, ensuring that your installation is always safe and current.
In addition, Composer creates and stores a graph of dependencies that features all the modules and extensions employed in your project. Therefore, in case, for example, a newer version of Magento, or such, a module comes out, Composer is capable of doing that upgrade on your installation based on the existing configuration so that Natalie will always be up to date.
2. Reusing third-party libraries
You can utilize your current PHP libraries and tools rather than replicating code within the Magento installation. Furthermore, it is very easy to include any library one finds in Packagist, the PHP package repository, and keep its versions up to date. In this way, not only does it save hard disk space, but makes update processes easier as well.
3. Elimination of compatibility challenges
It is worth noting that one of the advantages of Magento 2 is that it comes with the Composer component-based architecture with its Dependency Manager (or simply – it’s easy to install and manage new extensions and custom modifications).
In particular, when many people try to work on the same software in different areas and define different libraries, then Composer takes care of these libraries’ versions to make sure they do not clash. This can be termed ‘smart design’ since ‘dependency hell’ scenarios are hard to come by thanks to this. Thus, developers are able to focus on writing the core business logic of their extensions instead of worrying about such problems as compatibility for long periods of time.
4. Compliance with PHP-FIG guidelines
In addition to the absence of complexity concerns and redundant code, BSS Commerce are also pleased to note that Composer ensures Magento 2 adheres to the PHP-FIG standards. The PHP Framework Interoperability Group (PHP-FIG) advocates for best practices and interoperability among various PHP frameworks and components.
Therefore, individuals acquainted with these standards, including PSR-0, PSR-1, PSR-2, PSR-3, and PSR-4, can readily comprehend and contribute to the Magento codebase. Furthermore, components and libraries can be seamlessly shared and integrated across diverse projects.
Preparation: 3 Requirements to Run Magento Store
Before starting your Magento installation, it is essential to thoroughly review and verify all items listed in our checklist below.
1. Ensure Compliance with All Server Specifications
Magento 2’s performance on managed cloud hosting is contingent upon the server meeting essential specifications. Below is a detailed overview of the server requirements for Magento:
Operating System:
- Linux distributions (RHEL, Debian, Ubuntu, CentOS) only.
- No macOS or Windows support.
Hardware:
- Minimum 2GB RAM recommended, especially for upgrades. Swap file creation advised for systems with less than 2GB to prevent upgrade issues.
- Web Server: NGINX 1.x or Apache 2.4
Database:
- MySQL 5.6 & 5.7
- Percona 5.7
- MySQL NDB Cluster 7.4
- MariaDB 10.0, 10.1, 10.2
PHP:
- Versions ~7.3, ~7.4, or ~8.1
- Required extensions: ctype, mbstring, hash, curl, JSON (see full list for details)
- Mail Server: MTA (Mail Transfer Agent) or SMTP server
Security:
- Valid security certificate required for HTTPS (self-signed certificates not supported)
- TLS 1.2 or higher required by repo.magento.com and Paypal
- Browsers: Latest versions of Chrome, Edge, and Firefox on any OS. Safari supported on iOS 12+ (iPhones/iPads) and macOS. Chrome (mobile) supported on Android 4+.
Magento 2.4+ Specifics:
- Elasticsearch 7.6+ required for search functionality (MySQL no longer used for search)
- RabbitMQ 3.8 required for messaging queues
2. Stack Up The Right Technologies
There are server requirements to be met in order to ensure that Magento 2 can perform well on its managed cloud hosting service. Below is a full specification of the hosting server needed for the use of the Magento platform:
Besides the system prerequisites, the advised tech stack should also be a factor to consider. This will be discussed in detail below.
Magento assents the PHP framework as the base programming language for building up versions of the software while the current release supports PHP version 8.1. Code management systems tend to be extended, hence the need for Composer to work with codebase and additional Magento programs. At present, coding practices that are followed with respect to Magento 2 are PSR-0, -1, -2 and -3, although as for PSR-4, it is not a must but rather is highly recommended.
Some of the main enabling structures at the front end include CSS3, HTML5, RequireJS, KnockoutJS, and JQuery. Also, utilizing very efficient caching mechanisms such as Varnish and Redis, as well as object and database cache, brings forth a tremendous improvement in speed.
3. Get Authentication Credentials
Before attempting to download Magento, one must first get access to Adobe Commerce, and obtain the Composer which can be found at repo.magento.com.site.
In that quest, a profile for the Commerce Marketplace has to be created and used to create two authentication keys that are made up of 32-digit characters each. These keys should be tied to a MAGEID which is the primary contact’s username for this account who has access to download Adobe Commerce packages.
Here are the steps for your convenience:
Step 1: Go to the Commerce Marketplace and log in. If you do not have an account, please click on Register. Once you are logged in, click on your account name in the top right corner, and then click on My Profile.
Step 2: Select My Profile. In the Marketplace tab, locate Access Keys. Click on Create New Access Key and provide names for the keys. Afterward, click OK button.
Step 3: Click on the ‘Create A New Access Key’ button
You will now see the newly generated private and public keys associated with your account. Click on these keys to copy them to your clipboard. You are now one step closer to completing your Magento 2 setup.
How to Install Magento 2 Using Composer in 3 Easy Steps
Composer is a powerful tool for managing PHP dependencies, making it the preferred method for installing Magento 2. This guide will walk you through the steps of setting up your environment and installing Magento 2 using Composer:
Step 1: Use the command line or download link to install Magento Composer
Composer serves as a widely utilized dependency manager for PHP, facilitating the installation and management of packages for PHP applications. It can be installed via the command line or through a download link.
The installation process is as follows:
1. Installing Composer via the command line:
a) Initiate the download of the Composer installation file by executing the following command in your terminal: $ curl -sS https://getcomposer.org/installer | PHP
b) This command will retrieve the Composer installation file and save it as composer.phar in your current directory.
c) Transfer the composer.phar file to a directory included in your $PATH variable. You may use the following command to relocate it to /usr/local/bin/: $ sudo mv composer.phar /usr/local/bin/composer
d) Confirm the successful installation of Composer by executing the following command: $ composer –version
2. Installing Composer via a download link:
a) Go to the official Composer page and get the relevant Composer installer for your operating system.
b) When the download is finished, transfer the downloaded file to an appropriate folder which is included in your $PATH variable. For example, if you are working on macOS, you can move that file to /usr/local/bin/.
c) Now change the name of this file to composer (without .phar extension) by typing the following command in the terminal:
$ mv composer.phar composer
d) To check if Composer was successfully installed, run the command:
$ composer --version
Well done, you have installed Composer via the command line or by downloading it successfully. You can now use Composer to help you manage the dependencies for your PHP applications.
Step 2: Access the system as the file owner
1. Before the installation of Magento 2, it is very important to go to the path meant for the installation, such as public_html or var/www/html/magento2. In case you are logged into the Magento server, make sure that the file system owner of the server directory has write permission on the Magento file system.
For users of the bash shell, switch to the Magento file system owner and run the command in a single step with the following directive:
su <Magento file system owner> -s /bin/bash -c <command>
2. To run Magento commands from any directory, include <magento_root>/bin in your system PATH.
export PATH=$PATH:/var/www/html/magento2/bin
Alternatively, you may execute the commands using the following methods:
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 continue with the subsequent instructions to download the Magento Meta package.
Step 3: Obtain the Magento software
You can download the Magento 2 version directly from its official website. Alternatively, you can run a command using Composer to download a specific version of Magento 2.
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 <install-directory-name>
Adobe Commerce (Enterprise)
composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition <install-directory-name>
During the installation of Magento, you have the option to specify a particular version (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) by utilizing the aforementioned command.
IMPORTANT: If you want to use Composer to install Magento 2 in the respective folder (for example, public_html), do remember to put a dot (.) at the very end.
Now the time to download Magento has come, however, repo.magento.com username and password will be asked for entering by you. Log into the Magento Marketplace to get these details, then go to My Account on the top right corner, and finally, press the Access Keys to create your new SECURE KEYS.
- Public Key: Represents your username
- Private Key: Represents your password
After entering your repo.magento.com username and password, you will be prompted for store credentials. Respond with “Yes.”
Subsequently, Magento 2 will begin downloading onto your server.
Step 4: Configure permissions necessary for the installation of Magento 2.4
For the effective installation of Magento 2, the provision of the proper permissions for your Magento 2 Store is of paramount importance. There are recommended permissions that Magento clearly outlines and calls for their observance.
(a) The owner should have full control over all the files.
(b) The Web Server should be able to write to the var, app/etc, and pub folders.
(c) bin/magento should be made executable.
At this stage, it is important to run a few commands to change the permissions:
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
Step 5: Create a database for the Magento installation process
You can go through Setup Wizard or navigate to Magento 2 root directory then run this command to install Magento 2.
Remember to change options with your website information:
Command:
php bin/magento setup:install --base-url=http://mystore.com/ --db-host=localhost --db-name=mystore.com --db-user=admin --db-password=magento2 --admin-firstname=Magento --admin-lastname=User --admin-email=admin@mystore.com --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=UTC --use-rewrites=1
Take note: This command utilizes placeholder data. It is essential to replace this information with the specifics pertaining to your application.
After installation is completed, you will see the following message:
[SUCCESS]: Magento installation complete. [SUCCESS]: Magento Admin URI: /admin_im53pc
Your URL admin in Magento 2 is http://mystore.com/admin_im53pc.
So, you have successfully completed the installation of Magento 2 using Composer. It is now time to proceed with the necessary configurations.
Next, you will need to conduct a readiness check and initiate your Magento store.
Let’s checkout the New Magento 2 Application
10 Troubleshooting Tips for Installing Magento 2 via Composer
The Magento 2 installation guide provided by BSS Commerce is very clear. However, it should be noted that not all installations go as smoothly as the instructions provided, and many challenges are likely to come up. In these situations, you can look at some of the possible solutions given in this article:
1. Permission Errors
One of the common problems especially with Magento 2 installation is the permission issues. In this case, it is important to fix and set the right folders and file permissions. Files should be set to 644 permissions and folders to 755 permissions. Also, please ensure that the user of your web server owns all Magento files and folders.
2. Missing Dependencies
Another concern is the presence of missing dependencies. To fix it, go to the root directory of Magento 2 and run composer update or composer install commands.
3. “Fatal error: Allowed memory size exhausted” notification
This problem occurs when one is working with a very low PHP memory limit. To fix this, you could try to increase the memory limit within your php.ini file by adding the below line: memory_limit = 2G
If this adjustment does not yield results, you may also execute the following command in your terminal: php -d memory_limit=-1 /usr/local/bin/composer install
4. “Class ‘Locale’ not found” notification
This issue may occur if the PHP extension for the ‘intl’ package is not installed. You can rectify this by executing the following command in your terminal: sudo apt-get install php-intl
5. “The requested PHP extension ext-iconv * is missing from your system” notification
This issue may arise when the PHP extension for the ‘iconv’ package is not installed. To resolve this, run the following command in your terminal: sudo apt-get install php-iconv
6. “The requested PHP extension ext-mbstring * is missing from your system” notification
This issue may occur if the PHP extension for the ‘mbstring’ package is not installed. You can install the ‘mbstring’ package by executing the following command in your terminal: sudo apt-get install php-mbstring
7. “Could not open input file: composer.phar” notification
This issue may arise when the ‘composer.phar’ file is not found in the appropriate directory. Ensure that you are executing the command from the directory containing the ‘composer.phar’ file. If the file is absent from that location, you can download it from the Composer website and transfer it to the correct directory.
8. No ‘composer’ Command Found
The problem arises when Composer is not found on your system. You should Install Composer as recommended in the official article. Make sure to add composer path to your system’s environment variables. After the completion of the installation, execute the process again. Close and reopen your terminal if the problem still exists.
9. Version Compatibility Issues
Ensure that the extension version corresponds to the version of Magento you are using. Verify the necessary version from the extension provider. If it does not match, use composer require package_name:version to install the older version. It is advisable to always validate new versions on a staging environment before rolling them out.
10. Extension Not Found
Make certain that the appropriate package name is being utilized. Confirm with the extension vendor the exact name. Confirm that the repository is properly added in Composer. Fix repository issues and add a path to bsscommerce using the composer config repositories.bsscommerce composer <path> command. Verify the compatibility of the extension with the version of Magento that you are using.
Final Verdict
BSS Commerce are happy to inform you that Magento 2 has been installed successfully using Composer. This mode of installation is efficient and secure and allows easy installation of upgrades to avoid stagnation of the online store. Now that you have installed your Magento 2 stores, you can start customizing them and also begin product additions to grow your eCommerce business.
When you have learned about using Composer, we recommend you also take advantage of the Magento Development Service by BSS Commerce. Our service is developed exclusively for Magento, offering effective and secure hosting services, thus, you can devote your efforts on business enhancement without worrying about the website’s performance and safety.
Hopefully, these guidelines about how to install Magento 2 using Composer are helpful for you. Thanks for reading!