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
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
Managed Magento Hosting for an Instant Performance Boost
Build an optimized Magento 2 store in minutes & go BIG with your sales.
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.
- Extract Magento 2.4.1 files to your xampp/htdocs folder.
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.
Click Next, and browse to the path of the PHP in the XAMPP folder.
Now click Install to initiate the final step.
Launch the Command Prompt and run the Composer command to verify that it has been installed without any issues.
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.
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.
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.
Create a Database for Magento 2.4.1
Access localhost/phpmyadmin, create a database.
IMPORTANT Remember the name of the database you would create.
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.
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.
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.
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.
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.
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:
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
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.
Customer Review at
“Great speed, features, knowledgebase, dashboard, UX and fast, expert support. Very happy!”
Stefan [Management Consultant]
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]