How To Install Magento 2 on windows Machine

image
image
image
image
image
image

How To Install Magento 2 on windows Machine

Installing Magento 2 on a Windows machine involves setting up a robust local development environment tailored for eCommerce solutions. This process requires the installation and configuration of several components, including XAMPP, which provides the necessary Apache, MySQL, and PHP support. Additionally, Composer, a PHP dependency manager, is essential for managing Magento’s dependencies. Once these tools are installed, Magento 2 can be downloaded and configured to run locally. This setup allows developers to build, test, and customize their Magento stores in a controlled environment, ensuring a smooth transition to a live server when ready

Step -1. Create a virtual host

C:\Windows\System32\drivers\etc\hosts

To create a virtual host named “magento” on your Windows machine, follow these steps:

  1. Edit the hosts file:
    • Open C:\Windows\System32\drivers\etc\hosts in a text editor with administrator privileges.
    • Add the following line:
      127.0.0.1 magento.local

      This maps the custom domain magento.local to your local machine.

  2. Configure Apache:
    • Open the Apache virtual host configuration file, located at C:\xampp\apache\conf\extra\httpd-vhosts.conf.
    • Add the following virtual host configuration:

      apache

      <VirtualHost *:80>
      DocumentRoot "C:/xampp/htdocs/magento2"
      ServerName magento.local
      <Directory "C:/xampp/htdocs/magento2">
      Options Indexes FollowSymLinks Includes ExecCGI
      AllowOverride All
      Require all granted
      </Directory>
      </VirtualHost>
    • Ensure the DocumentRoot and Directory paths point to your Magento 2 installation directory.
  3. Enable Virtual Hosts in Apache:
    • Open C:\xampp\apache\conf\httpd.conf.
    • Ensure the line Include conf/extra/httpd-vhosts.conf is uncommented by removing the # at the beginning:

      apache

      # Virtual hosts
      Include conf/extra/httpd-vhosts.conf
  4. Restart Apache:
    • Open the XAMPP Control Panel.
    • Stop and then start the Apache server to apply the changes.

After completing these steps, you can access your Magento 2 site by navigating to http://magento.local in your web browser. This setup will help you simulate a live server environment, making local development and testing more convenient and realistic.

STEP 2. Download and Install Composer

Composer is an essential dependency manager for PHP, which is required to manage the various packages and libraries that Magento 2 relies on. Here’s how to download and install Composer on a Windows machine:

  1. Download Composer:
    • Visit the Composer website.
    • Click on the “Composer-Setup.exe” link to download the installer for Windows.
  2. Run the Composer Installer:
    • Open the downloaded Composer-Setup.exe file to begin the installation process.
    • Follow the prompts in the setup wizard. During the installation, ensure that PHP is correctly configured on your system. The installer will automatically detect the PHP executable.
    • Choose the default options unless you have specific requirements.
  3. Verify Composer Installation:
    • After the installation is complete, open the Command Prompt.
    • Type composer and press Enter. If the installation was successful, you will see the Composer version and a list of available commands.

Composer will now be available globally on your system, allowing you to install and manage dependencies for your Magento 2 project efficiently. This step ensures that all necessary libraries and packages for Magento 2 are properly installed and updated, facilitating a smoother development process.

STEP 3: Obtain Public and Private Access key from Adobe website

To install and manage Magento 2 packages, you need to obtain public and private access keys from Adobe (formerly Magento). These keys allow you to authenticate and download Magento software and updates. Follow these steps to get your access keys:

  1. Create an Adobe Account:
  2. Log In to Your Adobe Account:
    • Log in to your existing Adobe Commerce (Magento) account using your credentials.
  3. Navigate to Access Keys:
    • Once logged in, go to the Magento Marketplace by clicking on your account name and selecting “Marketplace” from the dropdown menu.
    • In the Marketplace, navigate to “My Access Keys” under the “Marketplace” section in your account dashboard.
  4. Generate New Access Keys:
    • Click on the “Create a New Access Key” button.
    • Enter a name for your new access key pair to identify it easily.
    • Click “Generate Keys” to create a new pair of access keys.
  5. Retrieve Your Keys:
    • You will see your new public and private access keys listed.
    • Copy these keys and store them securely, as you will need them during the Magento 2 installation process.

These access keys are required for the Composer setup in Magento 2, enabling you to download and update the Magento application and its components from the Magento repository. Ensure you keep these keys confidential to maintain the security of your Magento environment.

STEP 4: Write Bellow command  with Public and Private key Access

composer global config http-basic.repo.magento.com <public_key> <private_key>

Write the above command in the Windows command line (CMD)

STEP 5:  Download WIndoes Repository

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

Then

composer update

Then

composer install

STEP -6 Create Database

http://localhost/phpmyadmin/ create database

Step-7: Install Magento

php bin/magento setup:install –base-url=”http://acesoftech.local/” –db-host=”localhost:3308″ –db-name=”magento3″ –db-user=”myadmin” –db-password=”Angular13″ –admin-firstname=”admin” –admin-lastname=”admin” –admin-email=”saz3sumar@gmail.com” –admin-user=”admin” –admin-password=”Admin123!” –language=”en_US” –currency=”USD” –timezone=”America/Chicago” –use-rewrites=1

change the above information as per your information

STEP-8 Download and install Elsticserch and run

Elasticsearch is a critical component for Magento 2 as it powers the search functionality, enhancing the search speed and relevance on your eCommerce site. Follow these steps to download, install, and run Elasticsearch on your Windows machine:

  1. Download Elasticsearch:
  2. Install Elasticsearch:
    • Extract the downloaded ZIP file to a directory of your choice, for example, C:\Elasticsearch.
    • Open a Command Prompt with administrative privileges.
    • Navigate to the bin the directory inside your Elasticsearch folder. For example:
      cd C:\Elasticsearch\bin
  3. Run Elasticsearch:
    • Start Elasticsearch by running the following command:
      elasticsearch.bat
    • Ensure that Elasticsearch starts without errors. You should see log messages indicating that Elasticsearch is running.
  4. Verify Elasticsearch is Running:
    • Open a web browser and navigate to http://localhost:9200.
    • If Elasticsearch is running correctly, you should see a JSON response with information about your Elasticsearch instance.
  5. Configure Magento to Use Elasticsearch: (After Installation)
    • Log in to your Magento admin panel.
    • Navigate to Stores > Configuration > Catalog > Catalog > Catalog Search.
    • Set the “Search Engine” to “Elasticsearch” and configure the required settings such as Elasticsearch server hostname and port (default is 9200).
    • Save the configuration and test the search functionality on your Magento site.

By following these steps, you will have Elasticsearch installed and running on your Windows machine, ensuring your Magento 2 site benefits from robust and efficient search capabilities.

 

You may encounter error , fix it below

error

replace this code

C:\xampp822\htdocs\magento\lib\internal\Magento\Framework\Image\Adapter\GD2.php
OR
C:\xampp822\htdocs\magento\vendor\magento\framework\Image\Adapter

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;
}

Fix this  as well

Go to: C:\xampp\htdocs\magento\vendor\magento\framework\View\Element\Template\File – > Edit Validator.php using a text editor and find this line: Find this line

strpos($realPath, $directory)

Replace strpos($path, $directory)

Next Fix

Then, Open up app/etc/di.xml in the editor, find this line

“Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink” replace

“Magento\Framework\App\View\Asset\MaterializationStrategy\Copy”

Finally, your Magento should Install

[SUCCESS]: Magento Admin URI: /admin_e90kh8l
——————–

STEP 9: Reindex and Flush Cache

php bin/magento indexer:reindex

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy -f

php bin/magento cache:flush

Disable Two factors in magent0 2

php bin/magento module:disable Magento_AdminAdobeImsTwoFactorAuth Magento_TwoFactorAuth

===============================

Install Sample Data in Magento 2

php bin/magento deploy:mode:set developer

php bin/magento sampledata:deploy

php bin/magento setup:upgrade

php bin/magento cache:clean
php bin/magento cache:flush

php bin/magento setup:static-content:deploy en_US -f

error while compiling

curl -X PUT -H “Content-Type: application/json” http://localhost:9200/_cluster/settings -d “{ \”transient\”: { \”cluster.routing.allocation.disk.threshold_enabled\”: false } }”

curl -X PUT -H “Content-Type: application/json” http://localhost:9200/_all/_settings -d “{ \”index.blocks.read_only_allow_delete\”: null }”

path: C:\xampp822\htdocs\magento\lib\internal\Magento\Framework\Interception
OR
C:\xampp822\htdocs\magento\vendor\magento\framework\Interception

find this and repalce

$cacheId = implode(‘|’, $this->scopePriorityScheme) . “|” . $this->cacheId;

to
$cacheId = implode(‘-‘, $this->scopePriorityScheme) . “-” . $this->cacheId;

 

Summary:

Installing Magento 2 on a Windows machine involves a detailed process to establish a robust local development environment suited for eCommerce solutions. This setup includes several key components and configurations to ensure that the environment is well-prepared for development and testing. Below is a summary of the installation steps and configurations.

Initial Setup

Step 1: Create a Virtual Host

The first step is to create a virtual host on your Windows machine. This involves editing the hosts file (C:\Windows\System32\drivers\etc\hosts) to map the custom domain magento.local to your local machine’s IP address. Next, configure Apache by editing the httpd-vhosts.conf file located in C:\xampp\apache\conf\extra. Add a virtual host configuration pointing to your Magento 2 installation directory. Ensure the Apache configuration includes the virtual hosts file and then restart Apache to apply these changes.

Composer Installation

Step 2: Download and Install Composer

Composer, a PHP dependency manager, is essential for managing Magento’s dependencies. Download the Composer installer from the Composer website, run the setup, and follow the prompts. After installation, verify Composer by running composer in the command line, ensuring it is globally accessible.

Adobe Access Keys

Step 3: Obtain Public and Private Access Keys

To manage Magento 2 packages, you need public and private access keys from Adobe. Create an account on the Adobe Commerce (Magento) website if you don’t have one, log in, and navigate to “My Access Keys” in the Marketplace. Generate a new pair of keys and store them securely for later use in Composer setup.

Configuring Magento

Step 4: Configure Composer with Access Keys

Using the keys obtained, configure Composer by running the command:

composer global config http-basic.repo.magento.com <public_key> <private_key>

This command authenticates your Composer to access Magento repositories.

Step 5: Download Magento 2 Repository

Download Magento 2 using Composer with the command:

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

Then, update and install the required packages by running composer update and composer install.

Step 6: Create Database

Create a new database for Magento using phpMyAdmin (accessible via http://localhost/phpmyadmin/).

Step 7: Install Magento

Run the Magento installation command, specifying your base URL, database details, and admin credentials. Modify the command to reflect your setup.

Elasticsearch Installation

Step 8: Download and Install Elasticsearch

Elasticsearch is crucial for Magento’s search functionality. Download the appropriate Elasticsearch version, extract it, and run the elasticsearch.bat file. Verify it by navigating to http://localhost:9200. Configure Magento to use Elasticsearch by setting the search engine in the Magento admin panel.

Final Steps

Step 9: Reindex and Flush Cache

After installing Magento, reindex the data and flush the cache using 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

Optionally, disable two-factor authentication if necessary.

Install Sample Data

For sample data, switch to developer mode, deploy sample data, and update the setup:

php bin/magento deploy:mode:set developer
php bin/magento sampledata:deploy
php bin/magento setup:upgrade
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento setup:static-content:deploy en_US -f

Troubleshooting

If errors occur, such as issues with GD2 or interception, specific fixes include modifying code in the relevant files (GD2.php, Validator.php, etc.) and updating configurations in di.xml.

By following these steps, you will have a fully functional Magento 2 environment on your Windows machine, ready for development and testing. This setup provides a controlled environment that closely mimics a live server, ensuring a smoother transition to production.