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.

✨ Vultr and Linode are back on Cloudways! VIEW PLANS→

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

Updated on March 13, 2024

9 Min Read
install Magento 2 via Composer

Are you a developer struggling with the manual installation process of Magento 2? Even if you’re familiar with it, managing the libraries and dependencies can be cumbersome.

Enter Composer – a tool for dependency management within Magento 2 that streamlines the process. Installing Magento 2 via Composer provides a more streamlined and hassle-free experience, especially with the Command-Line Interface (CLI) playing an important role in Magento 2.4 onwards.

In this guide, we’ll explore the benefits of using Composer to install Magento 2 and provide easy-to-follow steps for a successful installation.

Advantages of Installing Magento 2 via Composer

Using Composer to install Magento 2 helps manage its components and dependencies, offering several advantages such as:

  • Reusing third-party libraries without bundling them with Magento 2 source code.
  • Reducing Magento extension complexity and compatibility issues using a component-based architecture with robust dependency management.
  • Adhering to PHP-FIG (Framework Interoperability Group) standards.
  • Repackaging Magento 2 code with other components.
  • Using Magento 2 in a production environment.

If you’re wondering how to install Magento 2 using Composer easily, follow this simple step-by-step guide on installing Magento 2 using Composer.

Requirements for Running Magento 2 Store

Before we can move into the section for Magento 2 installation using Composer, please check the following:

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 to install Magento using Composer successfully.

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:

$ mv composer.phar 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 face any technical issues, feel free to ask in the comments, and 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 in to 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.

Install Magento 1

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 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), do not forget to add the (.) dot at the end.

During this process, before downloading Magento, you would be asked to Insert your repo.magento.com username and password. For 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.

Install Magento 4 Download Magento

Step 4: Set Permission to Install Magento 2.4

To install Magento 2, you now need to set proper permissions for your Magento 2 Store. Magento has a set of recommended permissions that we have to apply.

a ) The owner must have full access to files.

b ) Web Server must have write permission on 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 {} \;        
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 Magento installation

Create an empty database with MySQL/MariaDB

Command:

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

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 that base-url (“http://yoururl/cloudways.com”) is your application url, db-host is the hostname or IP address of the server, db-name is the name of database, db-user is the username of the database and db-password is the password of your database. You can customize the admin’s first name, last name, and other parameters.

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

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

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

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

Magento Installation Steps

Let’s Check Out the New Magento 2 Application

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

Magento Frontend

Backend

Magento Application 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)

Since installing Magento 2 requires a lot of effort, store owners do not want to waste their time on technical stuff. Instead, they want to be more focused on their business growth. They prefer a solution that caters to their needs.

This is where Cloudways Platform comes in handy!

Cloudways’ user interface is designed to be intuitive and easy to navigate, making it accessible for non-technical individuals to manage their servers and Magento applications with minimal effort.

Furthermore, Cloudways provides all the necessary server requirements for the seamless operation of Magento 2, ensuring a smooth and hassle-free experience.

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.

Signup/Login to Your Account

Step 2: Select Magento Application

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

Select Application:

Select Application

  • Fill in the remaining fields to install Magento.

 install Magento.

 

Step 3: Choose Cloud Providers

  • Select the Cloud Provider of your choice.

Step 4: Select Server Size & Bandwidth

  • Select Server Size & Bandwidth according to your requirements.

Select Server Size & Bandwidth

Step 5: Define Server Storage

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

Install Magento 11 Server Storage

Step 6: Select Server Location

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

Select your server Location

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

click on the Launch Server 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:

Server Details

Application Details:

Application Details

Check Your Application:

Install Magento 16 Application

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! With this efficient, secure, and easily updatable installation method, you’re off to a great start in building your online store. Now that you have your Magento 2 store set up, you can begin customizing it and adding products to expand your business online.

In addition to using Composer, you can also benefit from Magento managed hosting with Cloudways. Our platform is optimized for Magento and provides high-performance, secure hosting, so you can focus on growing your business without worrying about website performance or security.

By taking advantage of these powerful tools, you can ensure that your Magento store is in top shape and ready to succeed.
So, start exploring the full potential of Magento 2 with Composer and Cloudways managed hosting, and take your online business to new heights!

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].

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

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

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now