Magento Tips & Tricks

Install Magento 2.4 on Windows Problem Solved

If you have tried to install Magento 2 on Windows – you have encountered some issues with it already. With each version the number of such errors is growing and on the latest Magento 2.4 we have three such errors now.

This is not a surprise – Magento 2 is not supposed to be runned on Windows system – that’s why it is not much tested on it.

You say – who needs to install Magento 2 on Windows anyway? Yes, sure, obviously we’re not going to use it alive in production on Windows local server. Its totally dumb. But you know. Some of the developers are working in the Windows operating system. And imagine – developing and coding Magento 2 themes and extensions. So yes – this could be needed sometimes.

And now we will begin – we will install the latest Magento 2.4 on the Windows local PHP web server and eliminate those errors one by one.

First we will clone the Magento repository. Create a new empty database. Do the composer install. And run the Magento installation command in the command line.

But stop. That’s not all. Starting from Magento 2.4 – ElasticSearch is required.  So we need to install it on Windows first. You can download its installation here:

Ok now everything is ready. Go go go: php bin/magento setup:install

Boom. Here goes the first error:

Magento 2.4 Installation 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 64:

  Wrong file

Lets see what is wrong here. Open: lib/internal/Magento/Framework/Image/Adapter/Gd2.php and find this code around lines 85:

This code is validating the url schema of the file. But in Windows files system – you will have something like this C:/LocalServer/WWW/Magento24/…

So in this case the scheme will be just “C”. And this is obviously not on this list. So let’s add it there (or “D” if you local server is installed on another drive):

So this one is fixed. Lets go again: php bin/magento setup:install

Ok. It’s installed now. Lets go to the backend. Oops here goes another one:

Magento 2.4 Template Validation Error

1 exception(s):

Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: ‘C:/WinNMP/WWW/magento24temp/app/code/Magento/Backend/view/adminhtml/templates/page/js/require_js.phtml’ in module: ‘Magento_Backend’ block’s name: ‘require.js’

Hmm. And why is this template invalid? Because validator is incorrectly fails for validating file path on Windows system in lib/internal/Magento/Framework/View/Element/Template/File/Validator.php around line 117:

What are we gonna do? Lets just bypass this validation making this condition always be true by adding “|| true” there:

Don’t forget – we are doing it to make it work on Windows for development purposes. I strongly don’t recommend doing anything like this on live production systems.

Great now we are able to login to the backend. But what happens if we need to re-compile it. For example after upgrading when installing the new module.

Let’s give it a try: php bin/magento setup:di:compile

And we have another one:

Magento 2.4 Compilation Error

In ErrorHandler.php line 61:

  Warning: file_put_contents(C:/WinNMP/WWW/magento24temp/generated/metadata/primary|global|plugin-list.php): failed to open stream: No such file or directory in C:\WinNMP\WWW\magento24temp\lib\internal\Magent

  o\Framework\Interception\PluginListGenerator.php on line 414

Why did this happen? The compiler was trying to create new files with “|” character in its name. It’s totally cool on Linux file systems but not allowed in Windows file systems.

To fix it we need to open this file: lib/internal/Magento/Framework/Interception/PluginListGenerator.php around line 411:

We will replace “|” with “_” in $key variable which contains the file name:

Now we will check how it works. Do the compile one more time: php bin/magento setup:di:compile

Yippee – compiled successfully. So your Windows Magento 2.4 installation is alive now. Install Magento 2.4 on Windows problem solved!

Have happy coding!

Leave a Reply

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