Installing Magento 2 is never an easy task. Since the very first release, there are many problems users may encounter when installing Magento 2.
With the latest release of Magento 2.4, things have become harder as Magento 2 now, requires Elasticsearch as a mandatory component.
To make a Magento 2 installation work properly in the Production environment, users are recommended to install Magento 2 in localhost first. Then transfer the local installation to a Magento 2 hosting and update store’s Baseurl, and reindex Magento 2.
In this tutorial, we will go through the process of installing Magento 2 (with Elasticsearch) in Localhost using Xampp. The operation system in this tutorial is Windows 10 but this guide should work well for Windows 7 also
This installation guide works with Magento 2.4.0, Magento 2.4.1 and Magento 2.4.2
Refer to this article if you are looking for a guide to install Magento 2.4.x on ubuntu with Elasticsearch
Step 1: Install Xampp and Compose
In this step, we will install 2 components that are required to run Magento 2 on localhost environment XAMPP and COMPOSER (for windows)
First of all, we will download and install Xampp, a web server solution stack package that helps developers to create and test their applications on a local webserver.
>Download Xampp here: https://www.apachefriends.org/download.html
Next, run set up file and proceed with all steps to install Xampp. In Select Components step, make sure to select Mysql and PHP, PHPmyadmin.
Now open XAMPP and start Apache and Mysql
Now we will install Composer on localhost.
Composer is a library management tool in PHP (Dependency Management), this tool saves us a lot of time with the necessary packages that your project needs to use, you just need to declare it, Composer will automatically download the code of the libraries through a community server.
>Download Composer Windows version here: https://getcomposer.org/Composer-Setup.exe
Now we will verify if Composer was successfully installed by opening Windows Command Promp and type
composer . If the command prompt screen returns this outcome > Composer was installed properly
Important note: Magento 2.4 and Magento 2.4.1 installation does not support Composer version 2
- Magento 2.4.2 and later are compatible with both Composer 1.x and 2.x. You don’t need to downgrade composer version if you are installing Magento 2.4.2
- Magento 2.4.1 and earlier are compatible with Composer 1.x only.
If you install Magento 2.4 or 2.4.1 on Composer 2, you will probably see this error message
- Root composer.json requires magento/composer-root-update-plugin ~1.0 -> satisfiable by magento/composer-root-update-plugin[1.0.0]. - magento/composer-root-update-plugin 1.0.0 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
By default, the version of composer for windows is the latest version
2.0.7. So to install Magento 2 properly on Windows we will need to downgrade Composer version to
Check current composer version by typing
composer in command prompt interface, sample output:
/ ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 2.0.7 2020-11-13 17:31:06 Usage: command [options] [arguments]
=> That means the current composer version is 2.0.7. We will need to downgrade Composer to 1.10.17 to install Magento 2.4
To downgrade the composer version, issue this command:
composer selfupdate --1
root@magentip:~# composer selfupdate --1 Warning: You forced the install of 1.10.17 via --1, but 2.0.7 is the latest stable version. Updating to it via composer self-update --stable is recommended. Upgrading to version 1.10.17 (1.x channel). Use composer self-update --rollback to return to version 2.0.7
Step 2: Install elasticsearch on windows
Elasticsearch is now a required application to install Magento 2.4. During installation process, the system will verify if Eleasticsearch was installed and configured properly. If there’s something wrong with Elasticsearch verification, the installation process will stop.
Download Elasticsearch here: https://www.elastic.co/downloads/elasticsearch
Next, unzip archived file and go to
Right click on
elasticsearch.bat and select run as administrator
Leave this window running on background
To check if Elasticsearch is running on your system, in your browser type:
If you see this result page => Elasticsearch is running properly
Step 3: Config php.ini
Before we will install Magento 2, make sure to install and enable all required PHP extensions and configure some PHP values to make the installation go smoothly
Enable required php extensions
As stated in Magento 2.4 system requirement, we need to install and enable the following php extension
On windows OS, all the extensions are automatically and periodically compiled by the PHP Group. You just need to enable these required extensions in php.ini
Go to C:\xampp\php\php.ini and add these lines after the [PHP] tag to enable PHP extensions.
[PHP] extension=php_intl.dll extension=php_soap.dll extension=php_xsl.dll extension=php_sockets.dll
The other extensions are enabled by default after we install Xampp, so we don’t need to include them here. Remember to save files before exiting.
You will see such error if you don’t enable the required PHP extensions
Problem 1 - php-amqplib/php-amqplib v2.10.1 requires ext-sockets * -> the requested PHP extension sockets is missing from your system. - php-amqplib/php-amqplib v2.10.1 requires ext-sockets * -> the requested PHP extension sockets is missing from your system. - Installation request for php-amqplib/php-amqplib v2.10.1 -> satisfiable by php-amqplib/php-amqplib[v2.10.1]. Problem 2 - magento/framework 103.0.1 requires ext-intl * -> the requested PHP extension intl is missing from your system. - magento/framework 103.0.1 requires ext-intl * -> the requested PHP extension intl is missing from your system. - Installation request for magento/framework 103.0.1 -> satisfiable by magento/framework[103.0.1].
Configure php settings
In php.ini file, search and change the following values as below
max_execution_time=18000 max_input_time=1800 memory_limit=4G
These values will keep the installation go properly without interuption.
Finally, restart apache to apply php settings by click on apache
Start button on XAMPP
Quick tip: You can quickly open php.ini on Xampp interface with this button
Step 3: Create database for Magento 2 website
Before we process the installation, we have to create a database for Magento 2 website to store all settings related to products, catalog, users, store configuration….
In Xampp interface, open PHPmyadmin by clicking on Admin button to open phpmyadmin (you can also type: localhost/phpmyadmin/ in browser to access phpmyadmin)
On phpmyadmin page, click on New => type database name => click on Create to create a new database. For example, I create magento2 database here
By default, Xampp does not set a password for MYSQL, so we will need to create a new root password for mysql.
On Xampp, click on Shell button to open command interface
Next, input the following command to change mysql root password
mysqladmin.exe -u root password yourpassword
yourpassword with your desired password
Now, to use phpmyadmin, you will also need to enter the new password. To make phpmyadmin automatically login with your new password, go to C:\xampp\phpMyAdmin\config.inc.php and insert your new password here
Step 4: Install Magento 2
Now every preparation steps are done and we can start installing Magento 2 on Localhost.
- First download Magento 2 with sample data here: https://magento.com/tech-resources/download .(you will be asked to log in with your account on Magento 2 website)
Next, unzip this archived file into a folder in xampp\htdocs folder. For example: C:\xampp\htdocs\magento24
Now, inside magento24 folder by holding shift key and click on Open Command Windows here
Now insert this command to start installing Magento 2 (make sure Elasticsearch, Apache, Mysql all are running before execute this command)
php bin/magento setup:install --base-url="http://localhost/magento24/" --db-host="localhost" --db-name="magento4" --db-user="root" --db-password="root" --admin-firstname="admin" --admin-lastname="admin" --admin-email="email@example.com" --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
Replace these values:
- –base-url: your magento 2 installation folder
- –db-name: your database name in step 3
- –db-password: your database password in step 3
Other values are optional, we can change later.
Now if everything is done properly, Composer will start to install Magento 2. The process will last for around 10 minutes, so take a break with your coffee and relax.
When everything is done, you will see this notification.
Congratulation, Magento 2.4 was successfully installed on localhost
Now if you go to your browser with this URL to access Magento 2 store: http://localhost/magento24 .You will probably see a blank page like this
I mention the fix for this issue here: fix Magento 2 Blank Admin Page Issue . Here’s how to fix this:
Go to: C:\xampp\htdocs\magento24\vendor\magento\framework\View\Element\Template\File
Edit Validator.php using a text editor and find this line:
$realPath = $this->fileDriver->getRealPath($path);
Replace with this code:
$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
The new file should be like this after editting:
Next, you will need to run these command to upgrade the database and deploy static view files
php bin/magento indexer:reindex php bin/magento setup:upgrade php bin/magento setup:static-content:deploy -f php bin/magento cache:flush
Wait for the process
C:\xampp\htdocs\magento24>php bin/magento setup:static-content:deploy -f Deploy using quick strategy frontend/Magento/blank/en_US 2476/2476 ============================ 100% 42 secs adminhtml/Magento/backend/en_US 2549/2549 ============================ 100% 36 secs frontend/Magento/luma/en_US 2493/2493 ============================ 100% 31 secs
Now reload your website and you will see the your new Magento 2 website on localhost
Step 5: Install sample data for Magento 2.4
Now we will deploy sample data for our new Magento 2.4 website on localhost. Sample data will fill your website with some products, categories and images so your website will look like this:
In command interface, issue this command to deploy sample data
php bin/magento sampledata:deploy
Next, reindex, deploy static view files and upgrade database
php bin/magento indexer:reindex php bin/magento setup:upgrade php bin/magento setup:static-content:deploy -f
Finally flush cache to apply changes
php bin/magento cache:flush
Well done! refresh your website and enjoy your new Magento 2.4 installation with sample data
Troubleshoot admin login authentication error
When logging to admin dashboard, you may see this error
Full error message:
Failed to send the message. Please contact the administrator You need to configure Two-Factor Authorization in order to proceed to your store's admin area An E-mail was sent to you with further instructions
To fix this issue, open Magento 2 Command prompt and run this command
php bin/magento module:disable Magento_TwoFactorAuth
This command will disable Magento 2 Two-Factor Authorization so you won’t see the error message in admin panel
Now refresh admin page and you will be able to log in to admin dashboard normally.
If you see the notification message: one or more indexers are invalid. Make sure your magento cron job is running, please refer to this tutorial to reindex your Magento 2 store
Installing Magento 2.4 on localhost is very frustrating and many users may give up because there’re too many issues during installation process. Just follow this tutorial step by step and drop a comment below if you need any help.
I believe you will have a proper Magento 2.4 installation on Localhost in just 30 minutes.
In the next tutorial, I will guide you on how to move Magento 2.4 from localhost to live production server, so stay updated with magentip.com to receive the latest tutorial on Magento 2.