How to install Magento 2 in local using xampp. - Magesan

How to install Magento 2 in local using xampp.

How to install Magento 2 in local using xampp.

Let’s download xampp from the link : https://www.apachefriends.org/download.html

After download. Please Install it by clicking next button and choosing the right path to install.

After Installation successfull. You need to open Apache control which look like given below image and need to Enable the services of Apache and MySql by clicking on Start button from Actions.

After Enabled the services. To check if xampp installed successfully or not you need to go to any of the Internet Browser and enter url : localhost

If it opened as given below image then you have installed xampp successfully.

Now Let’s Install Magento 2 with version of 2.4.5

Open Terminal or Command Prompt and Go to xampp installation directory (Mine is : D:\xampp8.1.6\htdocs) inside htdocs folder.

Inside D:\xampp8.1.6\htdocs You need to fire below command and hit enter.

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

After successfully dowloaded Magento 2 via above command.

You need to go to the newly created directory in Terminal with cd magento245

Now we are going to Install Magento 2 but before that we need to configure Elasticsearch first.

You can download Elasticsearch from here : https://www.elastic.co/downloads/elasticsearch

Or you can download from below link of elasticsearch-7.6.0.zip

https://drive.google.com/file/d/1-ljsBkFSTZHSSrS9r15TSLyBT3cwsXMg/view?usp=drivesdk

After download you need to extract the elasticsearch-7.6.0.zip file at htdocs folder (Mine at : D:\xampp8.1.6\htdocs)

After that you need to open separate Terminal to run Elasticsearch. After Open new Terminal you need to fire this command : .\bin\elasticsearch.bat at htdocs folder (Mine at : D:\xampp8.1.6\htdocs)

It will look like this.

To know if your Elasticsearch works fine or not you need to enter url : http://localhost:9200/ at Internet Browser.

It will return like below if your elasticsearch configured fine.

Before moving to Install Magento 2 we must need to create a db first.

You need to open http://localhost/phpmyadmin for creating database

I am creating db with name : magento245

CREATE DATABASE magento245;

Now we are ready to install Magento 2

You need to fire below command at magento245 folder (Mine is : D:\xampp8.1.6\htdocs\magento245)

php bin/magento setup:install --base-url=http://local.magento245.com --db-host=localhost --db-name=magento245 --db-user=root --db-password= --admin-firstname=admin --admin-lastname=admin --admin-email=admin@admin.com --admin-user=admin --admin-password=admin@123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --backend-frontname=admin --search-engine=elasticsearch7 --elasticsearch-host=localhost --elasticsearch-port=9200

After you fired this you will get lot’s of error msgs. You need to resolved them first.

1 Issue)

Go to : vendor/magento/framework/Interception/PluginListGenerator.php

Replace the line :
$cacheId = implode('|', $this->scopePriorityScheme) . "|" . $this->cacheId;

with below:
$cacheId = implode('-', $this->scopePriorityScheme) . "-" . $this->cacheId;

2 Issue)

Go to : vendor\magento\framework\Image\Adapter\Gd2.php

Replace the line in function validateURLScheme :
if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes)) {

with below:
if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename)) {

3 Issue)

Go to : vendor\magento\framework\View\Element\Template\File\Validator.php

Replace the line in function validateURLScheme :
$realPath = $this->fileDriver->getRealPath($path);

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

Yes. You are good to go now.

After you successfully Installed Magento 2 you need to set some elements to access the magento 2 admin and frontend.

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

Add this line of code at Last of the file

127.0.0.1 local.magento245.com
Go to : D:\xampp8.1.6\apache\conf\extra\httpd-vhosts

Add this line of code at Last of the file

<VirtualHost *:80>
    DocumentRoot "D:/xampp8.1.6/htdocs/magento245/pub/"
    ServerName local.magento245.com
    Header set Access-Control-Allow-Origin "*"
</VirtualHost>

After set these two configurations you need to Stop the Apache server and Start again to make configuration works.

One more setting you need to apply before processing.

You need to go to the http://localhost/phpmyadmin and open the database you have created (Mine is : magento245) after opened you need to open it’s one of the table `core_config_data`

find the path with “web/unsecure/base_url” and click on Copy like given screenshot

You need to edit path with : web/secure/base_url and click on Go button like given screenshot.

You need to fire commands before accessing Magento 2

You need to disable the module TwoFactorAuth to make Magento Admin works

php bin/magento module:disable Magento_TwoFactorAuth

After disble must need to fire below commands.

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento setup:di:compile
php bin/magento cache:clean
php bin/magento cache:flush

Yepee you have installed Magento 2 Successfully.

If you want to access admin you need to enter url at browser : http://local.magento245.com/admin

It will look like below. You can access admin by entering username and password which you have been set while installing.

Username : admin
Password : admin@123

The frontend will look like this.

The Magento 2 Installed Successfully.

OPTIONAL INSTALLATION (NOT RECOMMENDED) IF YOU WANT TO HAVE DATA WITH MAGENTO 2 LIKE (PRODUCTS, CATEGORIES, PAGES) BY DEFAULT.

IF YOU WANT TO DEPLOY SAMPLE DATA YOU NEED TO FIRE BELOW COMMAND

php bin/magento sampledata:deploy
IT COULD ASKS YOU TO ENTER USERNAME AND PASSWORD TO DEPLOY.
USERNAME : 32818eb1c6d0a5a161dc4c59ddc4cdb0
PASSWORD : 7c5895f1c1f6e78cfecd7525bc58f471

IT WILL TAKE SOME TIME TO BE DONE.

AFTER SUCCESSFULLY DEPLOYED YOU NEED TO FIRE BELOW COMMANDS AGAIN.

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento setup:di:compile
php bin/magento cache:clean
php bin/magento cache:flush

YEEPEEE YOU HAVE SUCCESSFULLY DEPLOYED SAMPLE DATA AND YOUR FRONTEND WILL LOOK LIKE THIS NOW.

Happy Coding…

Leave a Reply

Your email address will not be published. Required fields are marked *.

*
*
You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>