How to install Magento 2.4 on localhost (Xampp, Windows OS)

Magento 2.4 introduces several new requirements compared to earlier versions like 2.2 or 2.3. In particular, it requires Elasticsearch for catalog search and additional PHP extensions to be enabled. This guide will show you how to set up Magento 2.4 on Windows using XAMPP, including Elasticsearch installation and configuration tweaks.

Step 1: Install Elasticsearch

Magento 2.4 relies on Elasticsearch as the default search engine. Without it, Magento will not install successfully.

1. Download Elasticsearch:
Visit Elasticsearch downloads and download the ZIP package.

2. Extract the ZIP file:
Extract it to XAMPP’s htdocs folder, e.g.,

Install Elasticsearch

C:\xampp\htdocs\elasticsearch-7.10.2

3. Run Elasticsearch:
Navigate to the bin folder and run elasticsearch.bat as Administrator.

C:\xampp\htdocs\elasticsearch-7.10.2\bin\elasticsearch.bat

Install Elasticsearch

4. Verify Elasticsearch is running:
Open your browser and go to:

http://127.0.0.1:9200/

You should see JSON data indicating the Elasticsearch node is running.

Install Elasticsearch

Step 2: Prepare PHP for Magento 2.4

Magento 2.4 requires several PHP extensions. Open your php.ini (e.g., C:\xampp\php\php.ini) and ensure the following extensions are enabled:

extension=intl
extension=soap
extension=sockets
extension=xsl
extension=sodium

After editing php.ini, restart Apache from XAMPP Control Panel.

Step 3: Apply Magento Windows Fixes

Magento 2.4 installation on Windows may fail due to some issues inherited from earlier versions. Apply the following fixes:

Update Validator.php: Follow the guide here to avoid validation errors.
Update Gd2.php: Fix graphics-related installation issues using instructions here

Disable Two-Factor Authentication (optional):
If you encounter Authentication Errors, run:

php bin/magento module:disable Magento_TwoFactorAuth

Step 4: Install Magento 2.4 via Command Line

Once Elasticsearch and PHP are ready, you can install Magento using the CLI:

php bin/magento setup:install --base-url="http://127.0.0.1/magento-2.4.1/" --db-host="localhost" --db-name="magento_241" --db-user="root" --admin-firstname="admin" --admin-lastname="admin" --admin-email="admin@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="127.0.0.1" 
--elasticsearch-port=9200

Install Magento 2.4

Adjust the --base-url and database credentials according to your setup.
The installation may take a few minutes. Once completed, Magento will be ready to use.

Step 5: Access Your Magento Admin Panel

After installation, you can log in to the Magento backend at:

http://127.0.0.1/magento-2.4.1/admin

Use the admin credentials you specified during setup.

Troubleshooting Common Issues

Elasticsearch not connecting: Make sure it is running and reachable at 127.0.0.1:9200.
PHP extension errors: Double-check that all required extensions are enabled.
Authentication error: Disable Magento_TwoFactorAuth module if needed.
Permission issues: Ensure var/, pub/, and generated/ folders are writable.

Installing Magento 2.4 on Windows is more complex than previous versions due to Elasticsearch and additional PHP requirements. By following this guide, you can successfully run Magento 2.4 locally for development or testing.