This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How to Install and Set up Magento 2 on Localhost via XAMPP (A Complete Guide)

Updated on February 8, 2023

9 Min Read
Install Magento on XAMPP Localhost

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 on many platforms). In this tutorial, I will show you how to install and set up Magento 2 on a localhost using XAMPP.

XAMPP is a free and open-source cross-platform web server solution that allows you to run Magento 2 on your local machine for development and testing purposes. By the end of this tutorial, you will have a fully functional Magento 2 installation running on your localhost.

Benefits of Magento 2 on Localhost

These are the following benefits of installing Magento 2 on a localhost:

  • Running Magento 2 on localhost eliminates the need for a dedicated hosting plan, which can be costly.
  • A local installation of Magento 2 allows you to work on your website offline without an internet connection.
  • A localhost installation allows developers to test new features and extensions before deploying them to a live site.
  • A localhost installation allows you to customize your website without the risk of breaking the live site.
  • Localhost environments typically perform faster than remote servers because there is no latency from network communication.
  • By running Magento 2 on a localhost, you can protect your store from unauthorized access and hacking attempts.
  • A localhost installation allows you to easily back up and restore your website in case of a problem.

Experience the Cloudways Magento 2 Demo Store – No tech skills needed!

Experience a fully functional Magento 2 store built on top of renowned Cloudways hosting to deliver the fastest speeds.

Magento 2 Prerequisites for Localhost

Before installing Magento using Composer, you should check the prerequisites and system requirements that need to be installed.

  • Apache/NGINX Version 2.2 or 2.4
  • PHP Version 7.4.x or 8.1.x
  • MySQL/MariaDB Version 5.6.x, 5.7.x or Maria DB
  • Elasticsearch 7.6.x or higher

Take your Magento ecommerce store to the next level with Cloudways.

Get started today and experience lightning-fast loading speeds, seamless scalability, and 24/7 expert support.

Install and Set up XAMPP

I will cover the installation of Magento 2 on localhost so that you will not face any issues while following the process.

Step: 1 Download XAMPP Server

Go to Apache Friends and Download XAMPP Server.

magento-xampp-install

Magento strongly recommends installing XAMPP with PHP version 8.1.x for M2.4.5. Also, you can install Magento 2.4 with PHP 7.3, but it is not tested or recommended.

Step: 2 Install the XAMPP Server

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

Click the Next button.

magento-xampp-install-2

Leave the default selection as in the image. Click the Next button.

magento-xampp-install-3

Choose your installation folder. The default location is C:\xampp, but selecting a directory other than C:\ drive like D:\ or E:\ as per your convenience is recommended.

If you need to change, click the Browse icon to change your destination for the XAMPP program, and then click the Next button to go to the next step.

magento-xampp-install-4

Click the Next button.

magento-xampp-install-5

Click the Next button.

magento-xampp-install-6

Please wait until the setup wizard installs XAMPP on your computer.

magento-xampp-install-7

After setup is finished, you will see the option “Do you want to start the Control Panel now?”. Keep it selected. Click Finish to exit setup and enter XAMPP Control Panel.

magento-xampp-install-8

Step: 3 Configure PHP

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

magento-xampp-install-9

 

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

;extension=intl

;extension=soap

;extension=sockets

;extension=sodium

;extension=xsl

;extension=gd

Extend the memory_limit to 4G:

memory_limit=4G

After you’ve done, save and close the file. Then, click the Start button on 2 rows of Apache and MySQL to start them. Don’t quit XAMPP after this step, just let it run.

Step: 4 Configure Hosts File

Access to the directory C:\Windows\System32\drivers\etc\hosts.

magento-configure-host

Add the following line to the last row:

127.0.0.1 www.localhost.com

Open the XAMPP Control Panel and start Apache and MySQL applications.

magento-xamp-control

Create a Database in phpMyAdmin

Access the URL http://localhost/phpmyadmin, to create a database. Put in a database name (for example, Magento2) and click Create.

magento-phpmyadmin-2

Click the Next button to create the database.

magento-database

Database created successfully.

magento-show-database

Note: Remember the name of the database you would create as you’ll want to install Magento on it later on.

Install Composer for Magento

The latest version of Magento, open source 2.4.0 onwards, is compatible with Composer 2. So you need to install Composer 2 to download Magento 2 with the latest version.

The best way to do this is to download and run Composer-Setup.exe. This will install the latest version and set up your path to “call” Composer from any directory.

magento-composer-1

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

magento-composer-2

It’s optional to enter your proxy URL.

magento-composer-3

Now click the Install button to initiate the final step.

magento-composer-4

Click the Next button.

magento-composer-5

Click the Finish button.

magento-composer-6

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

magento-composer-version

Download Magento Using Composer

Next, cd to C:\xampp\htdocs and run the following command using Composer to Download a specific Magento 2 version.

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

Magento Open Source

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

Adobe Commerce (Enterprise)

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

By the above command, you can specify the specific version of Magento (2.0, 2.1, 2.2.1, 2.2.2, 2.2.3, 2.2.4, 2.2.5, 2.2.6, 2.3, 2.4). If not, skip the version and just run the command below:

magento-download

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.

magento-access-profile

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

magento-access-key

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.

magento-keys

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

magento-keys-enter

magento-key-enter-2

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:

magento-successfully-download

Install Elasticsearch for Magento 2

Elasticsearch is a highly recommended extension for Magento 2.4.X versions.

Download Elasticsearch 7.6.0: https://www.elastic.co/downloads/past-releases/elasticsearch-7-6-0 (Magento 2.4.x is tested with Elasticsearch 7.6.x only. You can use other 7.x versions at your discretion, but we recommend using the tested version of Elasticsearch.)

Extract the .zip file you’ve just downloaded. In a terminal window, cd to the extracted directory and run this command:

.\bin\elasticsearch.bat

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.

{
"name" : "DESKTOP-Jyoti",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "ONNrUlTWQCSoigYBy6WF9g",
"version" : {
"number" : "7.9.3",
"build_flavor" : "default",
"build_type" : "zip",
"build_hash" : "c41E4fgiueQSoiytrBW",
"build_date" : "2023-02-02T09:51:41.449Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "6.8.3",
"minimum_index_compatibility_version" : "6.8.3"
},
"tagline" : "You Know, for Search"
}

Install Magento 2 Using Command Line

Open the command prompt window. Next, cd to your Magento directory and 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 per your path, note down the admin username and password, and do not use the Elasticsearch port.

Replace these values:

  • –base-url: your magento 2 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.

magento-install

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.

magento-install-complete

Run the Commands

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

magento-app

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

Congratulations!

You have now successfully installed Magento 2.4.5-p1 on your localhost. You can start making your preferred customizations and launch a fully functional ecommerce store on the local machine.

Common Issues With Magento 2 Versions

There is a chance that you might encounter an issue during the Magento 2.4.1 or below versions of the Magento 2.4.5 installation process. Here are some of the most common ones, along with a solution.

1. 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:

magento-fix-error

2. 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

Summary

So that’s how you can install Magento 2.4.5-p1 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 to increase your sales and remove server-side management hassles. If you face any problem like a 500 Internal Server Error after implementing the above steps, please check here to fix the error.

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.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Jyotishna Kumari

Jyotishina is the Magento Community Expert at Cloudways and has 4 years of experience in web development. She has worked on e-commerce sites since the turn of the millennium and was working with Magento before version 1 was released. She loves to travel and explore new ideas whenever she finds time. Get in touch with her at [email protected].

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now