Amasty's team first decided to install Magento 2 as soon as its 0.42.0-beta1 version emerged in 2014. Since then, we’ve performed hundreds of thousands of Magento 2 installations for our clients.
That’s why, to make starting Magento for beginners easy, we decided to provide an in-depth Magento 2 installation guide. We address common methods, best practices, and possible errors.
Magento Installation Methods: An Overview
There are three primary methods to install Magento 2, each offering a distinct approach depending on your technical preference and environment:
Using Composer
Via GitHub
From an Archive (ZIP)
The Composer method is the most recommended and beginner-friendly. It allows you to install Magento with a single command, leveraging Composer’s powerful dependency management system. Magento Composer installation ensures a clean, modular, and easily maintainable store.
The GitHub method involves cloning the Magento 2 codebase directly from the official repository. This approach is best suited for developers who want direct access to the latest source code and are comfortable working with Git and managing updates manually.
The Archive (ZIP) method involves downloading Magento as a compressed archive and extracting it into your web server’s root directory. Although it may appear simpler, it still requires command-line interaction for dependency installation and permissions setup.
Localhost vs. General Magento Installation
It’s important to distinguish between localhost installations and general (production or staging) installations:
A localhost installation refers to setting up Magento on your personal computer or local server, ideal for development, testing, or learning. Common tools for this include Ubuntu (native or VM) or XAMPP for Windows/macOS.
A general installation is done on a remote or cloud server, typically intended for production or public-facing stores. It requires additional considerations such as SSL, domain configuration, and hosting scalability.
In this Magento 2 installation guide, we’ll cover all three methods and explain the specific requirements and steps for both local and remote setups.
Method 1: How to Install Magento 2 with Composer
Installing Magento via Composer offers several advantages:
Enables the use of third-party libraries without modifying the core source code
Minimizes the risk of code conflicts during development and upgrades
Allows for precise control over dependency versions
Supports semantic versioning for better version management
Adheres to the PHP Framework Interoperability Standard (PSR)
So, what are the steps to install Magento 2 using Composer? Let’s walk through them.
1. Install Composer
Before installing Magento, make sure that Composer is set up on your server. Use it to download the Magento 2 codebase.
2. Log in as File System Owner
Log in to the Magento server as the file system owner, or switch to a user with permissions to write to the Magento file system. If you use the bash shell, use the following directive to switch to the Magento file system owner and enter the command at the same time:
su -s /bin/bash -c
If you want to run Magento commands from any directory, add <magento_root>/bin to your system PATH. Here is the CentOS bash shell sample:
export PATH=$PATH:/var/www/html/magento2/bin
3. Get the Package
To get the Magento metapackage, do the following:
Log in to your Magento server as the Magento file system owner or switch to it.
Change to the docroot directory of the web server or to the directory that you configured as the virtual host docroot.
Create a new Composer project with the Magento Open Source or Magento Commerce metapackage using the following command:
Magento Open Source:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition
Magento Commerce:
composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition
During the Magento 2 installation process, you'll be prompted for authentication credentials. You need a set of Magento Marketplace keys for this step. If you don't have these keys, create a Magento Marketplace account, navigate to the "My Profile" section, and generate the keys in the "Access Keys" tab.
Composer allows you to customize your Magento 2 setup. Explore options like choosing sample data inclusion, specifying your desired PHP version, and more. Refer to the Composer documentation for additional customization possibilities.
Finally, pay attention to any errors or warnings that may appear during the installation process. In case you need to re-run the Magento compile command, use the following command:
php bin/magento setup:di:compile
Method 2: Magento Installation via GitHub
This method is best suited for people who contribute to the Magento Open Source codebase. To use this method, you should understand Composer and Git commands and be able to update system software and Magento extensions using them.
Installing Magento 2 via GitHub Without Sample Data
Step 1. Clone the Magento 2 repository from Github reps, or download the required release on the Github releases page.
Step 2. Create a new empty directory using this command:
git clone [email protected]:magento/magento2.git
Step 3. After the deployment is complete, enter the command:
composer install
Step 4. Install Magento 2. Here you can see an example of the Magento 2 installation command.
Example is relevant if Magento install directory is magento2ee, the db-host is on the same machine (localhost), and the db-name, db-user, and db-password are all magento:
bin/magento setup:install \ --base-url=http://localhost/magento2ee \ --db-host=localhost \ --db-name=magento \ --db-user=magento \ --db-password=magento \ --admin-firstname=admin \ --admin-lastname=admin \ [email protected] \ --admin-user=admin \ --admin-password=admin123 \ --language=en_US \ --currency=USD \ --timezone=America/Chicago \ --use-rewrites=1
Open the browser and visit your local link. Done!
But what if you want to install M2 with sample data?
Installing Magento 2 via GitHub with Sample Data
Step 1. Go to the webroot (not Magento 2).
Step 2. Clone the Magento 2 directory using the command:
git clone [email protected]:magento/magento2-sample-data.git
Step 3. Then, navigate to the cloned Magento 2 directory and run the command:
php -f dev/tools/build-sample-data.php -- --ce-source="your Magento CE install dir"
Now, symlinks to your Magento 2 installation are created.
Step 4. Next, you need to set ownership and permissions for Linux machine:
chown -R :your web server group name find . -type d -exec chmod g+ws {} \;
Step 5. Clear cache by going to the Magento 2 var/ folder and running the following command:
rm -rf cache/* page_cache/* generation/*
Step 6. Use the following commands to install sample data:
php bin/magento setup:upgrade php bin/magento setup:di:compile
Done!
Method 3. How to Install Magento 2 via a ZIP Archive
This is a relatively easy installation method, but it lacks many of the benefits of using Composer.
Step 1. Navigate to the Magento download page and download the latest Magento 2 version package in the needed archive type (choose whether sample data is needed).
Step 2. Upload the archive to your server, then extract it to the Magento root directory.
You can use the unzip/extract function to extract the Magento package for shared hosting. Or use the following commands if you are running on your server:
# File .tar.gz tar zxf # File .zip unzip
Then, add write permission for var, app/etc, pub folders:
chmod 777 -R var chmod 777 -R app/etc chmod 777 -R pub
Step 3. Start the Magento installation wizard and walk through the installation process.
How to Set Up Magento on Localhost
To run Magento on localhost means setting up the platform on your own computer instead of a remote server.
This installation is especially useful for developers, testers, and learners who want a safe, private environment to experiment with Magento features without risking a live site. It allows for faster development cycles, offline access, and full control over configurations, ideal for building custom themes, testing extensions, or learning Magento 2 from the ground up.
We’ve already mentioned that you can install Magento on localhost via GitHub. Other ways to perform local installations use:
Ubuntu (via a native Linux setup, VM, or WSL)
XAMPP (an all-in-one package for Windows/macOS)
Each method has its own pros and setup steps, depending on your operating system and development needs.
How to Install Magento on Ubuntu
Ubuntu offers a powerful and flexible environment for Magento development that closely mirrors a real server setup. This section walks you through configuring the LAMP stack, setting up Magento dependencies, and installing Magento 2 using Composer on Ubuntu.
Step 1. Firstly, check the Magento 2 requirements.
Step 2. After that, get the Magento software via Composer or an archive.
Step 3. Now you have to change permissions to read-write to install Magento files with the use of the command line.
Step 4. Next, install M2 on Ubuntu. Enter the following command in the command line:
bin/magento setup:install
--base-url=http://example.com/ \ --db-host=localhost --db-name=magento --db-user=magento --db-password=magento \ --admin-firstname=Magento --admin-lastname=Admin [email protected] \ --admin-user=admin --admin-password=12345 --language=en_US \ --currency=USD --timezone=America/Chicago --use-rewrites=1 \ --search-engine=elasticsearch7 --elasticsearch-host=es-host.example.com \ --elasticsearch-port=9200
Step 5. Check that everything works. Open your website backend and try to log in to the admin panel with the admin’s username and password.
You can find more information on this Magento 2 setup method with all samples of the code on the How to install Magento 2 on Ubuntu page.
How to Run Magento in XAMPP
XAMPP provides a beginner-friendly way to run Magento locally on Windows or macOS by bundling Apache, MySQL, and PHP into one package. In this section, you'll learn how to configure XAMPP for Magento 2 and complete the installation with minimal system setup.
Download and install XAMPP.
Navigate to the Magento website and get the package.
Go to the xampp/htdocs and make a folder called Magento.
Unzip the downloaded archive in the Magento folder, open the XAMPP Control Panel, and click the Config in the Apache section.
Choose the PHP (php.ini) from the shown menu.
Find these lines: extension=php_intl.dll \ extension=php_xsl.dll. Remove the ; sign at the beginning in an open document.
Return to the XAMPP Control Panel > run Apache and MySQL.
Write localhost/magento2 in the browser and choose the Agree and Setup Magento option.
After that, you have to complete the 6 steps of the Magento 2 installation process.
Open your browser, write localhost/magento, and localhost/magento/admin. Check if everything works fine.
For more information on this method, go to the How to install Magento 2 on XAMPP page, which describes each step in detail.
Troubleshooting Magento Installation Challenges
During the Magento 2 installation process, users may encounter common challenges. This section provides insights and solutions to help you navigate through potential issues:
File Permission Errors: In cases where users face file permission issues, review and adjust the ownership and permissions of Magento 2 files and directories. Utilize commands such as chown and chmod to ensure proper access.
Database Connection Problems: If the installation fails to connect to the database, verify the correctness of your database credentials, ensuring they match the values specified during the setup.
PHP Version Compatibility: Ensure that your PHP version aligns with Magento 2 requirements. Incompatibility issues may arise if the PHP version is too old or too recent.
Composer Dependency Resolution: If encountering dependency resolution problems with Composer, run composer install to fetch the required dependencies or update Composer to the latest version.
Read More: Magento – How to Start
Get Magento Installed Without the Headaches
Installing Magento 2 can be complex, especially with different methods, system requirements, and potential configuration issues. Whether you're setting up a development environment or launching a live store, even small mistakes can lead to performance or security problems down the road.
To save time and ensure a flawless start, consider using our Magento 2 Installation Service. Our experts will handle the entire setup – from server configuration to database preparation – so you can focus on growing your business, not fixing installation errors.
Let professionals take care of your Magento installation to start smoothly and confidently.
Frequently asked questions
You can download Magento 2 from the official Adobe Commerce website or via Composer using the Magento repository at repo.magento.com.
You need a compatible server (Linux recommended), PHP 8.1/8.2, MySQL 8, Elasticsearch, Composer, and proper file permissions.
Magento Open Source is free; Adobe Commerce (Enterprise) requires a paid license, with costs varying based on business size and features.