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
C:\Windows\System32\drivers\etc\hosts
To create a virtual host named “magento” on your Windows machine, follow these steps:
hosts
file:
C:\Windows\System32\drivers\etc\hosts
in a text editor with administrator privileges.127.0.0.1 magento.local
This maps the custom domain magento.local
to your local machine.
C:\xampp\apache\conf\extra\httpd-vhosts.conf
.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>
DocumentRoot
and Directory
paths point to your Magento 2 installation directory.C:\xampp\apache\conf\httpd.conf
.Include conf/extra/httpd-vhosts.conf
is uncommented by removing the #
at the beginning:
apache
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
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.
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:
Composer-Setup.exe
file to begin the installation process.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.
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:
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.
composer global config http-basic.repo.magento.com <public_key> <private_key>
Write the above command in the Windows command line (CMD)
composer create-project –repository-url=https://repo.magento.com/ magento/project-community-edition magento
Then
composer update
Then
composer install
http://localhost/phpmyadmin/ create database
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
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:
C:\Elasticsearch
.bin
the directory inside your Elasticsearch folder. For example:
cd C:\Elasticsearch\bin
elasticsearch.bat
http://localhost:9200
.Stores > Configuration > Catalog > Catalog > Catalog Search
.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
——————–
php bin/magento indexer:reindex
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
php bin/magento module:disable Magento_AdminAdobeImsTwoFactorAuth Magento_TwoFactorAuth
===============================
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;
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.
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.
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.
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.
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.
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.
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
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.