Installing Magento 2.4.3 Community Edition on a Windows machine and deploying on the localhost

Sean Byrne
15 min readNov 3, 2021

--

Boring but useful. Magento is an ecommerce platform that many use for their online sales. Installing it can be tricky though and here’s a tutorial to practice installing it locally before pulling the trigger to deploy it live.

Intro

Installations can be tricky. While going through this installation myself, I had to uninstall and reinstall at least three times before getting to a successful installation with a working admin page. However, let me be clear that this is not the best practice for deploying a live ecommerce store. This is more of a learning tool to familiarize oneself with the installation process. Or, someone could use this as their the development environment to work on new features before deploying them live. Even so, this won’t cover setting up a virtual environment, which is important when developing applications for the masses. This is strictly covering the steps for local installation and deployment from a Windows machine.

Methods/Documentation Process

This process consisted of:

  • reading the Magento2 documentation
  • 7 different installation guides (many with bad English, but helpful nonetheless)
  • I attempted the installation until I had a working admin page running from the localhost
  • I wrote down each step I took in the installation process during my second successful run through the installation
  • I edited the steps I took during my third successful installation

Many of the issues I encountered arrived from installing the wrong software or the wrong version of the software. So, before I got through the entire installation, I had to uninstall and re-install several times, which was time consuming and I hope that this tutorial can save you that time. I am grateful I went through that however, because now I’m more familiar with how to check and verify a complete install/uninstall.

Also, these are the links to all the resources I used to get through the install:

Machine Specs & Tech Stack

Machine Specs:

  • Dell Inspiron
  • Windows 10
  • 8 GB of ram
  • 64-bit OS
  • Intel Core i5 CPU

As you can see the computer I used is nothing spectacular.

Some editing tools you might find useful:

  • Notepad
  • VS Code

Tech Stack

  • XAMPP
  • Apache 2.4.51 (included in the XAMPP download)
  • PHP 7.4.25 (included in the XAMPP download)
  • MySQL (included in the XAMPP download)
  • Composer
  • ElasticSearch
  • Magento-ce-2.4.3 with sample data

Side note: Magento2 is incompatible with PHP v. 8.0.12 so it’s very important to download the XAMPP package with the compatible version of PHP, that being PHP 7.4.25

Overall, when I timed myself while running through the third installation it took roughly 4 hours 52 minutes. However, that included writing and editing documentation and taking screenshots. So I wouldn’t consider the 4hr 52mins to be the standard time, but more like a benchmark to plan around in case you want to do try this installation yourself. After this section, starts the installation steps. Good luck, if you try it.

Installation Steps

1. Download XAMPP

  • Find the download at https://www.apachefriends.org/download.html
  • Pick the download that has the PHP v. 7.4.25 because in this tutorial I’ll be demonstrating with Magento 2.4.3 and that version of magento is not compatible with PHP v. 8.0.12
  • Download the zip file to your Downloads folder

2. Install XAMPP

  • Click on the XAMPP installer file and run installation wizard
  • a “User Account Control” popup window will appear to ask “Do you want to allow this app to make changes to your device?” ⇒ click “Yes”
  • A ‘Warning’ pop-up may appear before running the wizard. Just click ‘OK’, because we’re about to address this in the XAMPP Installer wizard
  • After clicking “OK” the XAMPP setup should appear and click “Next >”
  • Install all of the components in the list so just click “Next >” if all of the boxes are checked
  • Now make your folder in the top of the C:\ drive directory(or whatever letter drive you predominantly use; F:\ drive, E:\ drive, etc…). In a lower folder, you might come across permission issues, which addresses the warning popup window we saw after opening up the XAMPP Install wizard.

⇒ Click “Next >”

  • Specify your language
  • The following window is just a promo for Bitnami and not important for the installation. I just deselect the checkbox next to “Learn more about Bitnami for XAMPP” and click “Next >”
  • Now the setup wizards will say “Setup is now ready to begin installing XAMPP on your computer.”

⇒ Click “Next >”

  • The install will begin and show you a progress bar in the setup wizard window
  • The install took about 4 mins for me, then the window will say it’s complete. Make sure the checkbox is checked and click “Finish” button

3. After Install is complete, configure the php.ini file

  • After you click the “Finish” button on the XAMPP install wizard, then the XAMPP control panel should popup and look like this:
  • To configure the php.ini file, find it at the following directory:

C:\xampp\php\php.ini

OR

  • Find it on the XAMPP console:

Open up the XAMPP console > click on the “Config” button to the right of “Apache” > a selection box will appear and click on “PHP (php.ini)”

  • Configure the php.ini by deleting the semicolons(;) in front of the lines of the following extensions:

; extension = intl

; extension = soap

; extension = sockets

; extension = sodium

; extension = xsl

  • Next, edit some settings in the same file. Find the following lines:

max_execution_time=120

max_input_time=60

memory_limit=512M

  • Change these to be equal to 18000, 1800 and 4G, respectively

4. Download Composer

  • After downloading the Composer-Setup.exe file, then run it to start the setup
  • Click “Install for all users (recommended)”
  • Keep “Developer Mode” unchecked & click “Next”
  • Use the Path they have for the PHP command-line & click “Next”.
  • No need to set up a proxy server & click “Next”
  • Click “Install”
  • Click “Finish”
  • Open a command-line window to verify composer installation

⇒ type: composer -v

⇒ Composer installation is verified with this resulting output:

5. Download ElasticSearch

  • download the zip file from their website:

https://www.elastic.co/downloads/elasticsearch

  • extract/unzip files once downloaded
  • They can be extracted in “Downloads” folder, it doesn’t matter where the extracted files are located
  • Go to the extracted files and open the bin folder:

~\Downloads\elasticsearch-7.15.1-windows-x86–64\elasticsearch-7.15.1\bin

  • Right click the second file from the top of the bin folder; it should be called elasticsearch and be 4KB in size

⇒ after right clicking on the file, then click:

“Run as Administrator”

⇒ a command-line should open — give it a moment to process

  • Verify successful install by going to a browser and typing:

127.0.0.1:9200

OR

localhost:9200

⇒ a json output should render on the browser window w/ the elasticsearch installation details

⇒ if an error pops-up just wait a few moments for composer to finalize in the command-line window, then refresh the browser

  • at this point the ElasticSearch installation is complete, but don’t close the command-line window running ElasticSearch. That needs be running simultaneously to run the Magento platform, so this window can be left open as we continue on
  • If you already did accidently close the command-line window running ElasticSearch, no worries. Just go back to the file and right click on it to “Run as Administrator” again and you’ll be back on track

6. Download Magento 2

It’s free and then you’ll be able to use the link below.

  • Download the magento zip file for the latest version of magento2 community edition (open source; free):

https://magento.com/tech-resources/download

  • In my case, at the time of writing that was magento-ce-2.4.3-p1
  • Check the box to get sample data and download
  • Download can be found at:

magento.com

OR

from the magento github repo

  • I chose to download from magento.com
  • After downloading the magento zip file BUT BEFORE extracting the magento zip file, create a new folder called magento2 w/ this Path:

C:\xampp\htdocs\magento2

⇒ extract contents of the magento zip file into the new folder you just created

Notice: this extraction takes a long time w/ or w/out sample data. For my computer, it took a little over 45 minutes and of course that will vary for everyone based on their computers and connections.

7. Install Magento 2

  • Once finished with the extraction, take a look at the files
  • Next, type in the web browser: localhost/magento2

⇒ this is to verify a successful installation

⇒ make sure that Apache & MySQL are running on XAMPP before verifying

  • Successful installation will redirect to a set-up page for the magento2 platform
  • Some of the tutorials that I followed said this “Set-Up” page appears in the internet browser after typing localhost/magento2 in the URL address bar

If you received errors and did not see a set-up page then CONGRATULATIONS! You are like me. Please continue on for the rest of the steps to get to a working admin page

If you did not receive errors and did see a set-up page render, then I am truly impressed. Congratulations! but I have no further instructions.

8. Create the database

  • create a new database with phpMyAdmin via the XAMPP Control Panel
  • Clicking on the “Admin” button next to MySQL will open up the phpMyAdmin page in your browser
  • On the admin page, click on “New” on the left hand menu => type the database name =>Click the “Create” button on the right hand side of the browser window
  • XAMPP’s default does not set a password for MySQL, so we’ll have to create a new mysql root password
  • Go to the XAMPP Control Panel and click on the “Shell” button — this opens up a command-line window
  • Next, type the following command to change the MySQL root password:

mysqladmin.exe -u root password yourpassword

  • Before executing the above command make sure you clicked the “Start” button next to Apache and MySQL
  • Replace yourpassword with the password you want to use. I put root as my password
  • In order to use phpMyAdmin, we will also need to enter the new password we just made into the phpMyAdmin config file. This will allow phpMyAdmin to automatically login with the new MySQL root password. Go to C:\xampp\phpMyAdmin\config.inc.php by clicking on the “Explorer” button on the XAMPP Control Panel and navigating the file browser
  • When you arrive at the file config.inc.php, open it up with Notepad and insert your new password where the red arrow is pointing in the screenshot, below. There’s another screenshot immediately after the first one that zooms in on the block of lines that contain the password config line. Use the password you just created in the command-line after you clicked on the “Shell” button in the XAMPP Control Panel.

9. Server Configuration

Magento is served from /var/www/html/magento2/pub. However, the rest of the file system is vulnerable because it is accessible from the browser. Therefore we’ll set the webroot to the pub/ directory in order to prevent site visitors from accessing sensitive areas of the file system from the browser.

  • Click on the “Explorer” button on the XAMPP Control Panel
  • Set the webroot to pub/by going to the file C:\xampp\apache\conf\extra\httpd-vhosts.conf
  • Paste this code at the bottom of the file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/magento2/pub"
ServerName yourname.magento.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>

… like in the screenshots below

Before pasting the block of code
After pasting the block of code
  • yourname.magento.com — this is the base url which you can set as whatever you wish. Ex: — ilovecats.magento.com, but I just used ‘yourname.magento.com’
  • Now, Open notepad with “Run as administrator”.
  • Open C:\Windows\System32\drivers\etc\hosts file in notepad
  • Sometimes, the hosts file won’t appear in the file browser so you have to change the file extension filter from .txt to All files
  • Open the hosts file (it’s an extensionless file) and add the following line at the bottom of the file:

127.0.0.1 yourname.magento.com

… like in the screenshot below:

  • Next, restart apache by clicking “Stop” then “Start” on the XAMPP Control Panel in order to apply the configurations we just made
  • Now make sure Apache is running, MySQL is running and ElasticSearch is running

We’re now ready to configure magento to our server and host configurations

  • Click on the “Shell” button to open another command-line window
  • Navigate to your magento folder:

cd C:\xamp\htdocs\magento2

  • Once in the magento2 folder copy the following command:

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

Replace these values if necessary:

  • –base-url: the one you used in the server config
  • –db-name: your database name
  • –db-password: your database password

The other values are not important for installation, and can be changed later.

Now if everything is done properly, Composer will start to install Magento 2.

10. If you get the following error, then follow the given solution below

Error :

In PatchApplier.php line 170:

Unable to apply data patch Magento\Theme\Setup\Patch\Data\RegisterThemes for module Magento_Theme. Original exception message: Wrong file

In Gd2.php line 72: Wrong file

Solution:

Here, Image Adapter is trying to open the image files (‘open function in Gd2.php line 72). The validateURLScheme function always returns false because it is checking for URL format but local files fall under this type of format, so it returns false.

Find validateURLScheme function in vendor\magento\framework\Image\Adapter\Gd2.php file. at line 94. Replace function with this:

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;

}

  • The only change is && !file_exists($filename) text added at line 98.
  • SIDE NOTE: it might be easiest to do this in a code editor like VS code or a similar tool that shows the line numbers, but the same thing can be done with Notepad, if you don’t want to download an IDE
  • Save the file and run install command in the command prompt again:

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

  • The output should look like the following screenshot. It means your magento2 installation is successful. Congratulations !!

Now if you go to your browser with this URL to access Magento 2 store: http://yourname.magento.com .You will probably see a blank page like this

Solution:

  • Go to C:\xampp\htdocs\magento2\vendor\magento\framework\View\Element\Template\File
  • Edit the Validator.php file after you find this line:

$realPath = $this->fileDriver->getRealPath($path);

  • Replace with this segment:

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

  • It should look like this after editing:
  • Save the file.
  • Then, open up app/etc/di.xml
  • Find the line Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink and replace with Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
  • Save the file.

Next, you will need to run the following commands to update the database and deploy static view files

  • Run: php bin/magento indexer:reindex
  • Run: php bin/magento setup:upgrade

… give it a moment

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

… again, give it a moment

  • Then, run: php bin/magento cache:flush
  • Then: php bin/magento catalog:images:resize
  • This last one takes a while, about 30 minutes
  • Now go back to the internet browser verify because the website should be live (don’t forget: Apache, MySQL and ElasticSearch all need to be running to see the website render in the internet browser)
  • Here’s what it looks like with the sample data

11. Reaching the main objective: Getting a working admin page

  • go to your admin page by typing in the internet browser address bar:

http://yourname.magento.com/admin

  • login to the admin page. The login credentials should be Username: admin and Password: Admin@123456
  • You’re going to see the following message:

Solution:

  • Open a command-line window, go the C:\xampp\htdocs\magento2 directory, and run this command:

php bin/magento module:disable Magento_TwoFactorAuth

This command will disable the Two-Factor Authorization requirement so you won’t see the error message when logging-in again.

  • Refresh the login page
  • Enter your login credentials again

You should now be able to access the admin page and it should look similar to this:

Congratulations!

You made it to the finish line and you now have a working installation of the Magento 2 platform served from the localhost of a Windows machine

--

--