Installing Magento 2 on Windows is an ideal way for local development and creating a safe environment for testing.
This blog shows you how to install Magento 2 on Windows 10/11 using XAMPP.
Steps for Installing Magento 2 on Windows
Before you start installing, here is a table with all the needed software for Magento 2 installation on Windows.
| Requirements | Description |
| XAMPP on Windows | Provides the core server stack. Download a version from Apache Friends that includes PHP 8.1, 8.2, or 8.3. |
| PHP Configuration | Several PHP extensions (intl, soap, xsl, sockets, zip, gd) must be enabled by editing the php.ini file in the XAMPP control panel. |
| Database | A blank database (e.g., magento2) must be created. You can do this using phpMyAdmin, which comes with XAMPP (http://localhost/phpmyadmin). |
| Composer on Windows | The PHP package manager used to download Magento. You must download the Composer-Setup.exe installer from getcomposer.org. |
| Elasticsearch / OpenSearch | This is mandatory. Magento 2.4+ will not install without it. You must download and run Elasticsearch (e.g., version 7.17.x) or OpenSearch separately. |
| Magento Auth Keys | Free authentication keys from the Magento Marketplace are required by Composer to download the Magento files. |
Step 1: Install XAMPP
- Go to the Apache Friends > download the XAMPP installer for Windows. Make sure the version includes PHP 8.1, 8.2, or 8.3.
- Run the installer and follow the setup prompts.
- Install XAMPP to the default location (C:\xampp).
- Once installed, open the XAMPP Control Panel.
- Start the Apache and MySQL services.
Step 2: Install Composer
- Go to the getcomposer.org page > download the Windows Installer (Composer-Setup.exe).
- Run the installer.
- Complete the setup and add it to the correct path is: C:\xampp\php\php.exe.
- Complete the rest of the installation steps.
Step 3: Install & Run Elasticsearch (Mandatory)
Magento 2.4+ will not install without a search engine.
- Go to Elasticsearch & Download the Windows ZIP file for the latest 7.x version.
- Unzip the folder to a simple location, like C:\elasticsearch.
- Go into the bin folder (C:\elasticsearch\bin) and double-click the elasticsearch.bat file.
- A new command window will open and run the server. You must leave this window open the entire time you are working on your Magento store.
Step 4: Configure PHP
- Open XAMPP Control Panel and select PHP(php.ini).
- Remove the semicolon (;) from the beginning of each one to enable them:
- extension=intl
- extension=soap
- extension=xsl
- extension=sockets
- extension=zip
- extension=gd
- Save and close the php.ini file.
- Stop and then Start the Apache service for the changes to take effect.
Step 5: Create Your Database
- Open your browser and go to http://localhost/phpmyadmin/.
- Click on the “Databases.” Under “Create database,” enter a name and click “Create”.
Step 6: Download Magento 2 (via Composer)
- Open the XAMPP Control Panel and click the “Shell” button. This opens a command prompt in the correct location.
- Navigate to your htdocs folder, which is the root directory for all web projects. Type: cd htdocs
Run the Composer create-project command to download Magento. (This may take 10-15 minutes).
composer create-project --repository=[https://repo.magento.com/](https://repo.magento.com/) magento/project-community-edition=2.4.7-8 magento2
- Go to the Magento Marketplace, log in (or create an account), go to “My Profile” > “Access Keys,” and generate a new key pair. Use the Public Key as your username and the Private Key as your password.
Step 7: Run the Magento Install Command
After Composer finishes, all the files will be in C:\xampp\htdocs\magento2. In the same XAMPP Shell, navigate into your new project folder: cd magento2
Now, run the single setup:install command to tell Magento how to set up your store.
Copy this full command, paste it into your shell, and press Enter:
php bin/magento setup:install --base-url="[http://127.0.0.1/magento2/](http://127.0.0.1/magento2/)" --db-host="localhost" --db-name="magento2" --db-user="root" --db-password="" --admin-firstname="admin" --admin-lastname="admin" --admin-email="[email protected]" --admin-user="admin" --admin-password="AdminPassword123" --language="en_US" --currency="USD" --timezone="America/New_York" --use-rewrites="1" --backend-frontname="admin" --search-engine="elasticsearch7" --elasticsearch-host="localhost" --elasticsearch-port="9200"
Post-Install Fixes & Troubleshooting
Admin Panel gives a 404 “Not Found” Error
Symptom: The storefront at http://127.0.0.1/magento2/ works, but the admin panel at http://127.0.0.1/magento2/admin gives you a 404 error page.
Cause: This is the most common issue with XAMPP. It happens because Apache’s URL “rewrites” (the mod_rewrite module) are not configured to work with Magento’s directory structure out of the box.
The Solution (The “Pub” Directory Fix): This is the exact solution you had in your original article. It’s a well-known workaround for XAMPP.
- Go to your C:\xampp\htdocs\magento2\pub\ folder.
- Copy the index.php and .htaccess files.
- Paste them into your root folder: C:\xampp\htdocs\magento2\ (and overwrite if asked).
- Open the new index.php file (the one in the root folder) in a text editor.
- Find this line: require __DIR__ . ‘/../app/bootstrap.php’;
- Change it by removing the ../: require __DIR__ . ‘/app/bootstrap.php’;
- Save the file.
- Go to phpMyAdmin , select your magento2 database, and click the SQL tab. Run this SQL query to update the database paths:
SQL
INSERT INTO core_config_data (path, value)
VALUES
('web/secure/base_static_url', 'http://127.0.0.1/magento2/pub/static/'),
('web/unsecure/base_static_url', 'http://127.0.0.1/magento2/pub/static/'),
('web/secure/base_media_url', 'http://127.0.0.1/magento2/pub/media/'),
('web/unsecure/base_media_url', 'http://127.0.0.1/magento2/pub/media/')
ON DUPLICATE KEY UPDATE value = VALUES(value);
Finally, run a cache flush from your command line: php bin/magento cache:flush
Admin Panel is a Blank White Page
Symptom: You go to the admin URL, and the browser loads a completely blank white screen. No error, no text.
Cause: This is a specific, known bug when running Magento on Windows. A file validator in Magento’s code has an issue with the Windows-style file paths (which use a backslash \ instead of a forward-slash /).
The Solution (Edit Validator.php):
- Navigate to the file: C:\xampp\htdocs\magento2\vendor\magento\framework\View\Element\Template\File\Validator.php
- Open this file in your text editor.
- Find the isPathInDirectories function (around line 114).
- Find this line of code inside the function: $realPath = $this->fileDriver->getRealPath($path);
- Replace that one line with this code, which adds a str_replace: $realPath = str_replace(‘\\’, ‘/’, $this->fileDriver->getRealPath($path));
- Save the file and refresh your admin page. It should now load.
The Entire Site is Extremely Slow
Symptom: Every single page load, on both the admin and the storefront, takes 10-30 seconds.
Cause: This is often a Windows networking issue where “localhost” is resolved very slowly. Using “127.0.0.1” (the direct IP address for your local machine) is almost always faster.
The Solution (Change Base URL to 127.0.0.1):
- Go to phpMyAdmin (http://localhost/phpmyadmin/) and open your magento2 database.
- Find the core_config_data table and click “Browse.”
- Find the rows for web/unsecure/base_url and web/secure/base_url.
- Change their value from http://localhost/magento2/ to http://127.0.0.1/magento2/.
- Run a cache flush from your command line: php bin/magento cache:flush
- Now, access your site using http://127.0.0.1/magento2/ in your browser. You should feel a significant speed improvement.
Now, try this solution and install Magento 2 on Windows. If this process overwhelms you, our Magento 2 developer can manage this task for you with complete ease.