How to install Magento 2?
There are several ways to install Magento 2:
In this step-by-step Magento 2 download guide, we will walk you through the entire installation process, covering all the methods.
Important note: Check Magento system requirements before installing.
Method 1. Using Composer to Install Magento (Metapackage)
Installing Magento via composer has several advantages:
- allows the use of third-party libraries without having to link them to source code
- reduces the number of conflicts
- provides different versions of dependencies
- semantic versioning
- Composer supports the PHP Framework Interoperability standard.
So what are the steps of Magento 2 installation via Composer?
Step 1. Pre-launch
Check the following: whether you set up the server and created the Magento file system owner to run any commands from the command line and to set up a Magento cron job.
Then complete prerequisites and install the composer.
Finally, get authentication keys in your Magento account.
Step 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 <Magento file system owner> -s /bin/bash -c <command>
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
Step 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 <install-directory-name> |
Magento Commerce:
composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition <install-directory-name> |
Enter your Magento authentication keys when prompted.
If any errors appear in the process of Magento 2 installation using the command line, make sure there are no typos and if errors remain, contact Magento support.
Now, the setup wizard will help you to end the installation process.
Pro tip: If you want to install sample data, do the following:
Step 1. Go to the Magento 2 root directory.
Step 2. Run the following command:
php bin/magento sampledata:deploy
php bin/magento setup:upgrade
After that, the composer.json file will be updated, and the sample data will be installed.
In case you need to re-run the Magento compile command, use the following command:
php bin/magento setup:di:compile
Be prepared for the fact that you may have to wait a bit.
Method 2. Contributor Magento install
Warning: This method is for people who contribute to the Magento Open Source codebase. To use this method, you should understand Composer and Git commands and can update system software and Magento extensions using them.
Let’s see how to install Magento 2 via Github.
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 installing command.
Example is relevant if Magento install directory is magento2ee, the db-host is on the same machine (localhost), and that 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. ?lone 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
Method 3. How to install Magento 2 via ZIP archive?
This is a relatively easy installation method, but it lacks many of the benefits of using Composer. So how to download Magento?
Step 1. Navigate to the Magento download page and download the latest Magento 2 source code 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 <filename>
# File .zip
unzip <filename>
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.
That's it!
Below you will find some more useful info on Magento 2 installation on Ubuntu and the localhost with XAMPP.
How to set up Magento 2 on Ubuntu?
Step 1. Firstly, check Magento 2 requirements.
Step 2. After that, get the Magento software by using Composer or by getting the 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.
Installing Magento on the localhost with XAMPP
Step 1. Download and install XAMPP.
Step 2. Navigate to the Magento website and get the package.
Step 3. Go to the xampp/htdocs and make the folder called Magento.
Step 4. Unzip the downloaded archive in the Magento folder, open the XAMPP Control Panel, and click the Config in the Apache section.
Step 5. Choose the PHP (php.ini) from the shown menu.
Step 6. Find these lines: extension=php_intl.dll \ extension=php_xsl.dll. Remove the ; sign at the beginning in an open document.
Step 7. Return to the XAMPP Control Panel > run the Apache and MySQL.
Step 8. Write localhost/magento2 in the browser and choose the Agree and Setup Magento option.
Step 9. After that, you have to complete 6 steps of the Magento 2 installation process.
Step 10. 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 the localhost with XAMPP page, which describes each step in detail.
The Magento installation process is very complex, as is the installation of extensions. To quickly master the process of installing modules, check out the How to install Magento 2 Amasty extensions article. Or you can use Magento 2 Installation Service to avoid all possible technical issues and Magento installation problems with the help of our experts at the very beginning.
Login and Registration Form