How to Install Magento 2
If you are visiting this post that means you are on the stepping stone in E-commerce world! And, you have made the right choice to select Magento 2 as the platform. I’ll guide you through the installation process of Magento 2.
Make sure you fulfill some basic Magento 2.x system requirements prior to installing Magento 2. You can also install Magento 2 via command line.
There are three ways to install Magento 2:
Let’s understand each method.
-
Install Magento 2 from the Archive File
- Visit the Magento Download Page. Download the latest Magento 2 package from any of the archive types (zip, tar.gz, tar.bz2), with or without sample data.
- Now upload the zip file to the server and extract it to Magento root directory.
- For shared hosting users, you can unzip or extract the package.
- For the local server, follow the commands below:
12345# File .tar.gztar zxf <filename># File .zipunzip <filename> - Run below command to add write permission for var, app/etc, pub folders.
123chmod 777 -R varchmod 777 -R app/etcchmod 777 -R pub - Now run Magento setup wizard and finish installation process.
-
Install Magento 2 via composer
A composer is a tool for dependency management in PHP. To learn more about the composer, visit https://getcomposer.org/doc/00-intro.md
Similar to above method, Magento core code is stored under /vendor directory and updating is possible through Magento admin.
Collect your authentication keys from here. Navigate to “My Access Keys”, enter a descriptive “Name” and generate a new set of keys.
Enter the following command in the terminal:
1composer create-project --repository-url=https://repo.magento.com/ magento/project-community-editionYour public key is the username, and the private key is the password which is needed to be entered after which the Magento 2 is ready to install. Just go through the Setup Wizard and install it now.
That’s it for the installation of Magento 2 via composer without sample data.
Now I’ll show you how to install sample data. Navigate to Magento 2 root directory through the terminal, and run the following command:
12php bin/magento sampledata:deployphp bin/magento setup:upgradeWhen you run the above two commands, composer.json file will be updated and the sample data will be installed. If you are asked to re-run the Magento compile command, enter the following:
1php bin/magento setup:di:compileSit back and wait for some time while the command is being executed.
-
Install Magento 2 via Github
Follow the below steps:
- Clone Magento 2 repo from github.com/magento/magento2 or download a necessary release github.com/magento/magento2/releases.
- Create a new empty directory.
- Run the following command:
1git clone git@github.com:magento/magento2.git - Wait for the deployment to be finished.
- Enter the following command:
1composer install - Install Magento 2Example of the command that installs Magento 2. Check the base-url, db-name, db-password, admin-email, and admin-password to match your local setup.
1php -f bin/magento setup:install –base-url=<server-url> --backend-frontname=<admin-url-key> --db-host=<db-host-name> --db-name=<db- name> --db-user=<db-user-name> --db-password=<db-password> --admin-firstname=<admin-firstname> --admin-lastname=<admin-lastname> --admin-email=<admin-mail-id> --admin-user=<admin-user> --admin-password=<admin-password> --language=<your-locale-language> --currency=<default-currency> --timezone=<timezone> –use-rewrites=1 - Open your browser and visit your local link
- Magento 2 is now installed!
To install Magento 2 via Github with sample data, follow the below steps:
- Go to the web root which is not Magento 2.
- Run the below command:
1git clone git@github.com:magento/magento2-sample-data.git - Navigate to cloned Magento 2 directory.
- Run the below command:
1php -f dev/tools/build-sample-data.php -- --ce-source="your Magento CE install dir" - For Linux machine, you need to set ownership and permissions:
12chown -R :your web server group namefind . -type d -exec chmod g+ws {} \; - Clear cache. Navigate to the Magento 2 var/ folder and run the below command:
1rm -rf cache/* page_cache/* generation/* - To install the sample data, run the below commands:
12php bin/magento setup:upgradephp bin/magento setup:di:compile
So that was all about Magento 2 installation
You can always refer the https://experienceleague.adobe.com/docs/commerce-operations/installation-guide/overview.html for more details or ask your doubts in the Comments section below. I’d be happy to help
Best wishes for your online store success with the help of latest Magento 2.4.6 features and security!
Feel free to share the tutorial with Magento Community via social media
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
2 Comments
After looking at a number of the blog articles on your blog, I really appreciate your way of blogging. I bookmarked it to my bookmark website list and will be checking back soon.
Thanks!