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.

How To Install Magento 2 on Localhost

June 16, 2021

5 Min Read
Install Magento on XAMPP Localhost

After the official release of Magento 2, users were eager to install it on their local machines or staging websites to check out the new features. However, as many developers reported, installing Magento 2 on the localhost proved to be quite a challenge. 

In this article, I will explain how to install Magento in localhost XAMPP using Composer in a step-by-step tutorial.

Magento 2 has very specific server requirements that require a lot of server configuration and tweaking, along with setting up Composer (not a default option at many platforms). 

Let me clear up why Composer is really important for Magento 2. Composer is an essential requirement for managing the Magento system, extensions, the involved dependencies, and for declaring libraries for the project.

Before you start, you need to have these things at hand:

1: XAMPP Server installed on your computer with the latest PHP 7.3 or 7.4.

2: Download Magento 2.4.1 along with sample data (You can download Magento 2 from this link)

Install Magento on XAMPP 1

3:Here are the basic Magento 2.4.1 server requirements:

    • Apache Version 2.2 or 2.4
    • PHP Version 7.3.x or 7.4.x
    • MySQL Version 5.6.x, 5.7.x
    • Elasticsearch 7.6.x or higher

Scalable, Super Fast, & Secure Magento Hosting

Our Clients Love us because we never compromise on these features

I will cover the entire process of installing Magento 2 on localhost so that you would not  face any issues in replicating the process:

  • Open the XAMPP server and start Apache and MySQL applications.

Install Magento on XAMPP 1

  • Extract Magento 2.4.1 files to your xampp/htdocs folder.

Install Composer

Download and run Composer-Setup.exe. This will install the latest version and set up your path so that you can “call” Composer from any directory.

Install Magento on XAMPP 2

Click Next, and browse to the path of the PHP in the XAMPP folder.

Install Magento on XAMPP 4

Now click Install to initiate the final step.

Install Magento on XAMPP 5

Install Magento on XAMPP 6

Launch the Command Prompt and run the Composer command to verify that it has been installed without any issues.

Install Magento on XAMPP 7

 

After installing the composer, you must enable the extension (php_intl.dll) in the php.ini file. To enable the extension, edit php.ini and uncomment the line “extension=php_intl.dll” and just remove the semicolon “;” from the starting of the line. Next, restart the XAMPP control panel.

Book a Personalized Cloudways Product Demo With One of Our Expert

Install Elasticsearch for Magento 2.4.1

Elasticsearch is a highly recommended extension for Magento 2.4.1.

Download and install the latest version of Elasticsearch from here. Once installed, run the bash file as an administrator. 

Install Magento on XAMPP 8

 

You can also check the availability of Elasticsearch on port:9200. Type local:9200 in the browser and you will get the details of the installed Elasticsearch extension.

Install Magento on XAMPP 9

Create a Database for Magento 2.4.1

Access localhost/phpmyadmin, create a database. 

IMPORTANT Remember the name of the database you would create.

Install Magento on XAMPP 9

Magento 2.4.1 Installation

First, unzip the downloaded Magento 2.4.1 file to xampp/htdocs/. After this, go to the Magento 2 folder (inside the htdocs folder).

Hold the Shift key and right-click, and select “Open command window here”. This will open a command prompt on the location.

Install Magento on XAMPP 11

In the command prompt, execute the command:

php bin/magento setup:install --base-url="http://localhost/magento2/" --db-host="localhost" --db-name="dbmagento241" --db-user="root" --admin-firstname="admin" --admin-lastname="admin" --admin-email="[email protected]" --admin-user="admin" --admin-password="admin123" --language="en_US" --currency="USD" --timezone="America/Chicago" --use-rewrites="1" --backend-frontname="admin" --search-engine=elasticsearch7 --elasticsearch-host="localhost" --elasticsearch-port=9200

Please note: Assign the base URL as per your path, note down the admin username and password and do not the Elasticsearch port.

Install Magento on XAMPP 12

Be patient as it could some time to install all instances and required modules for setting up Magento 2.4.1. 

After the installation, you will end up with these results.

Install Magento on XAMPP 13

If you hit the URL, you might won’t see the updated content with sample data on the storefront.

For that, you need to run the following commands.

php bin/magento indexer:reindex

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy -f

php bin/magento cache:flush

Now hit the URL (usually, localhost/magento2) or the base URL that you set earlier for the installation.

Install Magento on XAMPP 14

Congratulations! You have now successfully installed Magento 2..4.1 on your localhost. You can now start making your preferred customizations and launch a fully functional ecommerce store right on the local machine.

Optimize Magento Speed Like a Pro

Subscribe now and get a free ebook to your inbox.

Thank You

Your Ebook is on it’s Way to Your Inbox.

Problems During Magento 2.4.1 Installation

There is a chance that you might encounter an issue during the Magento 2 installation process. Here are some of the most common ones, along with a solution.  

  • Blank Grey Page – Magento Admin Panel

All you have to do is go to the directory path …\vendor\magento\framework\View\Element\Template\File\Validator.php

 In the function isPathInDirectories, add a line.

$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));

Refer to the following image for the point where you need to insert the line:

Install Magento on XAMPP 15

  • If You Get an Authentication Error

If you couldn’t log in to the Magento Admin Panel and encounter an authentication error, simply run the following command in the Composer:

php bin/magento module:disable Magento_TwoFactorAuth

Install Magento on XAMPP 16

Final Words

So that’s how you can install Magento 2.4.1 on the localhost using the Composer. Once you are ready to take your store live, you don’t need to worry about performance because Cloudways Managed Magento Hosting is here for increasing your sales and taking away the server-side management hassles. Just focus on building an awesome Magento 2 store and Cloudways will take care of the rest. And if you have any issues while installing Magento 2, you can go ahead and ask me via the comments section.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Customer Review at

“Great speed, features, knowledgebase, dashboard, UX and fast, expert support. Very happy!”

Stefan [Management Consultant]

Fayyaz Khattak

Fayyaz, a passionate Motorbike tourist, works as a Team Lead — Magento Community at Cloudways - A Managed Magento Hosting Platform. His objective is to learn & share about PHP & Magento Development in Community. You can contact him 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!