Skip to content
Search
  • ServicesPage
  • Our workPage
  • BlogPage
  • AI solutionsPage
  • Contact usPage
All articles

How to Install Magento 2 on Localhost via XAMPP server on Windows

Shafi · · 8 min read · Magento

How to Install Magento 2 on Localhost via XAMPP server on Windows

In this blog, I will guide you through the step-by-step process of installing Magento 2.4.5 on your local computer using XAMPP.

How to Install Magento 2 on Localhost via XAMPP server on Windows

I recommend visiting this link before starting the installation to ensure everything goes smoothly: https://experienceleague.adobe.com/en/docs/commerce-operations/installation-guide/overview

Installation Requirements for Magento 2.4.5:

You can visit this link to check all the system requirements.https://experienceleague.adobe.com/en/docs/commerce-operations/installation-guide/system-requirements

Here’s what I’ll be using:

  • OS: Windows 11
  • SERVER: Apache 2.4.58 (Win64)
  • RAM: 16 GB ( support – 8gb, 12gb)
  • PHP: 8.1.25
  • MariaDB: 10.4.32
  • Composer: 2.8.4
  • Elasticsearch: 7.17.0

Install and configure XAMPP

Step 1: Download XAMPP

Download link: https://www.apachefriends.org/download.html

We recommend installing XAMPP with PHP version 8.1.25, as this is the version Magento recommends for Magento 2.4.5.

OR

Direct link: https://sourceforge.net/projects/xampp/files/XAMPP%20Windows/8.1.25/xampp-windows-x64-8.1.25-0-VS16-installer.exe

Step 2: Install XAMPP

After downloading XAMPP, double-click on the file to install it on your computer.

Step 3: Configure XAMPP

In the XAMPP Control Panel, click Config button on “Apache” row, and click “PHP (php.ini)“.

How to Install Magento 2 on Localhost via XAMPP server on Windows

In the php.ini file, find these rows and remove; before each row:

Enable “intl“, “xsl“, “soap“, “gd”, “sodium”, “zip”, and “sockets” extensions in the configuration file by searching for the extensions by pressing ‘ctrl+f’ as shown in the below images. Then remove the semicolon to uncomment it before the line.

How to Install Magento 2 on Localhost via XAMPP server on WindowsHow to Install Magento 2 on Localhost via XAMPP server on Windows

Now Save and close the file at last. Stop and restart the Apache.

Note: Most PHP extensions are enabled by default. If you face any issues, review them one by one, make the necessary changes, then save the file and restart the server.

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=2G

Now Save and close the file at last. Stop and restart the Apache.

Step 4: Configure hosts file

Open C:\Windows\System32\drivers\etc\hosts. You can open this file click after right button and select as Run as Administrator. Add the following line to the last row:

127.0.0.1 www.localhost.com

Step 5: Create a database

For Magento2, we have to create a database. Firstly, open the web browser and hit the URL “http://localhost/phpmyadmin” to open the phpMyAdmin page. Then, by using the “new” button in the menu section on the left, create a database by the name “magento2” or by another name of your choice.

How to Install Magento 2 on Localhost via XAMPP server on Windows

Part 2: Install Elasticsearch

Download Elasticsearch from this link: https://www.elastic.co/downloads/past-releases/elasticsearch-7-17-0 and install it.

Extract the Zip file in the htdocs folder of the XAMPP installation directory after it has been downloaded. To do that, right-click the elasticsearch zip file and select extract files, and then select the htdocs destination path and press ‘Select’.

How to Install Magento 2 on Localhost via XAMPP server on Windows

After successful extraction, run the bash file as an administrator.

How to Install Magento 2 on Localhost via XAMPP server on Windows

You will get the output below.

How to Install Magento 2 on Localhost via XAMPP server on Windows

***Note: Please don’t close this window until the completion of the Magento 2.4 installation. Otherwise, it will show up an error.

Please wait for a while to get the installation done. Then type “localhost:9200” in the browser and you’ll get details of the installed Elasticsearch extension.

The output will be identical as seen in the image below:

How to Install Magento 2 on Localhost via XAMPP server on Windows

Install Composer for Magento

You need to install the Composer latest version download and run Composer-Setup.exe. This will install the latest version and set up your path to “call” Composer from any directory.

How to Install Magento 2 on Localhost via XAMPP server on Windows

Click the Next button and browse the PHP path in the XAMPP folder.

How to Install Magento 2 on Localhost via XAMPP server on Windows

It’s optional to enter your proxy URL.

How to Install Magento 2 on Localhost via XAMPP server on Windows

Now click the Install button to initiate the final step.

How to Install Magento 2 on Localhost via XAMPP server on Windows

Click the Next button.

How to Install Magento 2 on Localhost via XAMPP server on Windows

Click the Finish button.

How to Install Magento 2 on Localhost via XAMPP server on Windows

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

Run composer

How to Install Magento 2 on Localhost via XAMPP server on Windows

Or

Run composer -V

How to Install Magento 2 on Localhost via XAMPP server on Windows

Part 3: Download Magento using Composer

After install composer and then go to the XAMPP folder and then go to the htdocs folder ( D:\xampp8125\htdocs ) and run the following command:

Magento Open Source:

shell
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.5 <install-directory-name>

Just change <install-directory-name> to magento2(As your wish project name)

For example: composer create-project —repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.5 magento2

Adobe Commerce (Enterprise):

shell
composer create-project --repository-url=https://repo.magento.com/magento/project-enterprise-edition:2.4.5

Note: Enterprise edition is paid. Since we want to learn and so now skip it and run community edition and then see the image below:

Next, enter your Magento authentication keys. Public and Private Keys are created and configured in your Magento marketplace account.

Navigate to the Account name in the top right of the page and select My Profile.

How to Install Magento 2 on Localhost via XAMPP server on WindowsHow to Install Magento 2 on Localhost via XAMPP server on Windows

Next, click on the Access keys from the Marketplace tab.

How to Install Magento 2 on Localhost via XAMPP server on Windows

Click Create a New Access Key. Enter a specific name for the keys (for example, the name of the developer receiving the keys) and click OK.

How to Install Magento 2 on Localhost via XAMPP server on Windows

Copy the Public Key in the username and the Private Key in the password to install Magento.

How to Install Magento 2 on Localhost via XAMPP server on WindowsHow to Install Magento 2 on Localhost via XAMPP server on Windows

It should take a while for the composer to download and install all the necessary modules. When everything is finished, this is what you should see:

How to Install Magento 2 on Localhost via XAMPP server on Windows

During Magento 2.4 installation, you may encounter some errors. To prevent such errors, you first need to make some tweaks to Magento files.

To prevent this error:

How to Install Magento 2 on Localhost via XAMPP server on Windows

Go to the project folder and then go to this open directory path and file this type \vendor\magento\framework\Image\Adapter\Gd2.php and replace it with:

php
private function validateURLScheme(string $filename) : bool { $allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
$url = parse_url($filename);
if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename)) {

return false;

}

return true;

}

Next, go to the project folder (Suppose: ‘magento2’) or you can change directory path cd to your Magento directory and run this command:

For example: cd magento2

And then see below:

How to Install Magento 2 on Localhost via XAMPP server on Windows

Open the command prompt window. Next, cd to your Magento directory and execute the command:

code
php bin/magento setup:install --base-url="http://localhost/magento2/" --db-host="localhost" --db-name="dbmagento2" --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 per your path, note down the admin username and password, and do not use the Elasticsearch port.

Replace these values:

  • --base-url: your magento2 installation folder
  • --db-name: your database name while creating the database
  • --db-password: your database password
  • --db-user: a database user with full permission. We’ll be using the default root user.
  • --db-password: the password of your database user. Leave it blank if you’re using ‘root’ database user
  • --admin-firstname: Admin first name
  • --admin-lastname: Admin lastname
  • --admin-email: Admin email address
  • --admin-user: the username which you’ll be using to log into Admin Panel
  • --admin-password: the password which you’ll be using to log into Admin Panel
  • --language: the language which you’ll be using in your Admin Panel and your storefront. Use language code like en_US.
  • --admin-email: change it to your email
  • --currency: set the default currency to use in your storefront.Enter php bin/magento info:currency:list for a list of supported currencies along with their codes
  • --timezone: change to the timezone that you’re in. Refer to the list of supported timezones for a better idea on what to fill.
  • --url-rewrites: set to 1 to enable Web Server Rewrites. This will help with your site ranking.
  • --backend-frontname: set your Admin URL. Omitting this parameter will result in a randomly generated URL for your Magento Admin path (e.g., admin_jkhgdfq)
  • --search-engine: set the version of Elasticsearch that you want to use for this Magento installation. The default is elasticsearch7
  • --elasticsearch-host: the hostname or IP address where Elasticsearch is running. The default is localhost
  • --elasticsearch-port: the port number that Elasticsearch is listening to. The default is 9200

Other values are optional, we can change them later.

Now, if everything is done properly, Composer 2 will start to install Magento 2. The process will last for around 10 minutes.

How to Install Magento 2 on Localhost via XAMPP server on Windows

Be patient, as it could take some time to install all instances and required modules to set up Magento 2.4.5.

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

How to Install Magento 2 on Localhost via XAMPP server on Windows

After this, we’ll have to make some additional tweaks in order to make Magento work with Windows, like so:

Open this directory path and file.

In app\etc\di.xml, replace Symlink with Copy

html
<virtualType name="developerMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory">
<arguments>
<argument name="strategiesList" xsi:type="array">
<item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item>
<item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>
</argument>
</arguments>
</virtualType>

And then open this directory path.

In vendor\magento\framework\View\Element\Template\File\Validator.php, replace line 138 with:

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

Finally, run these commands:

code
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/pub/) or the base URL you set earlier for the in base-url during the installation.

For Admin: Access the url with http://localhost/magento2/pub/admin.

Note: If your above the URL is not working, then you follow the below:

Additional tweaks for Magento 2.4.5 and above:

Starting from Magento 2.4.5, it’s now mandatory to serve content from from the /pub/ folder in order to ensure better security. This is why additional tweaks are required in order to make your Magento 2.4.5 version work properly.

Step 1: Copy the index.php and .htaccess files from /pub/ to your root folder.

Step 2: Find the below line in the index.php (in the root folder):

code
require __DIR__ . '/../app/bootstrap.php';

and replace it with

code
require __DIR__ . '/app/bootstrap.php';

Step 3: Go to the Magento 2 database which you recently created (in http://localhost/phpmyadmin) and find the table core_config_data using this SQL query:

SELECT * FROM core_config_data

In this table, you’ll want to insert these rows in:

Path | Value

web/secure/base_static_url | http://localhost/magento2/pub/static/

web/unsecure/base_static_url | http://localhost/magento2/pub/static/

web/secure/base_media_url | http://localhost/magento2/pub/media/

web/unsecure/base_media_url | http://localhost/magento2/pub/media/

Replace magento2 with your Magento install directory

Insert rows manually:

How to Install Magento 2 on Localhost via XAMPP server on Windows

Insert rows with SQL queries:

sql
INSERT INTO `core_config_data` (`config_id`, `scope`, `scope_id`, `path`, `value`, `updated_at`) VALUES (NULL, 'default', '0', 'web/secure/base_static_url', 'http://localhost/magento2/pub/static/', current_timestamp());· INSERT INTO `core_config_data` (`config_id`, `scope`, `scope_id`, `path`, `value`, `updated_at`) VALUES (NULL, 'default', '0', 'web/unsecure/base_static_url', 'http://localhost/magento2/pub/static/', current_timestamp());· INSERT INTO `core_config_data` (`config_id`, `scope`, `scope_id`, `path`, `value`, `updated_at`) VALUES (NULL, 'default', '0', 'web/secure/base_media_url', 'http://localhost/magento2/pub/media/', current_timestamp());· INSERT INTO `core_config_data` (`config_id`, `scope`, `scope_id`, `path`, `value`, `updated_at`) VALUES (NULL, 'default', '0', 'web/unsecure/base_media_url', 'http://localhost/magento2/pub/media/', current_timestamp());

Your newly added rows should look something like this:

How to Install Magento 2 on Localhost via XAMPP server on Windows

Now clear cache using:

code
php bin/magento cache:flush

Now you can access your Magento frontend with your configured base-url. And refresh your frontend. You should now be able to see a blank page like this when access your frontend via configured base-url:

New base-URL: http://localhost/magento2/

How to Install Magento 2 on Localhost via XAMPP server on Windows

And our backend URL: http://localhost/magento2/admin

*Note: if you face this error when trying to log into your Magento Admin account: “You need to configure Two Factor Authorization…”

How to Install Magento 2 on Localhost via XAMPP server on Windows

Try running this command:

code
php bin/magento module:disable Magento_TwoFactorAuth

And then this error will be finish.

Part 5: Import sample data (optional)

Run this command to import sample data:

code
php bin/magento sampledata:deploy

After running this command, if you encounter any errors, go to your project’s root folder (magento2). There you’ll find a file named auth.json.sample. Rename it to auth.json, and then paste your Magento public and private authentication keys into this file.

Then again, this command to import sample data:

code
php bin/magento sampledata:deploy

After importing data is complete, run:

code
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:clean

Now refresh the frontend, and you should see the default Magento store with the Luma theme and sample data.

How to Install Magento 2 on Localhost via XAMPP server on Windows

That’s it! I hope you’ve successfully installed Magento 2 on your localhost. You can now access both the frontend and backend URLs. Enjoy your Magento setup!

Have a project in mind?

Tell us what you need. We get back to you as soon as possible.

Start a project