6

I am installing Magento 2.3 locally on Windows 10 with xampp. I downloaded the archive from Github, unzipped to c:\xampp\htdocs\magento2, and ran the installer from localhost/magento2/setup in my browser.

The installer finished with no errors, however when I go to the admin page, I get a blank page with a grayish background. When I go to localhost/magento2, I get this

I get this

When I look in magento2/var/log/system.log, there are some errors that say stuff like the following (each of these errors is repeated several times for a list of different file names)

main.ERROR: A symlink for "C:/xampp/htdocs/magento2/lib/web/requirejs/require.js" can't be created and placed to "C:/xampp/htdocs/magento2/pub/static/adminhtml/Magento/backend/en_US/requirejs/require.js". Warning!symlink(): Cannot create symlink, error code(1314) [] [] ) [] []

main.CRITICAL: Invalid template file: 'C:/xampp/htdocs/magento2/app/code/Magento/Backend/view/adminhtml/templates/page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js' [] []

EDIT:

I got the admin page working by changing the code in magento\lib\internal\Magento\Framework\View\Element\Template\File\Validator.php

The original code was

public function isValid($filename)
{
    $filename = str_replace('\\', '/', $filename);
    if (!isset($this->_templatesValidationResults[$filename])) {
        $this->_templatesValidationResults[$filename] =
            ($this->isPathInDirectories($filename, $this->_compiledDir)
                || $this->isPathInDirectories($filename, $this->moduleDirs)
                || $this->isPathInDirectories($filename, $this->_themesDir)
                || $this->_isAllowSymlinks)
            && $this->getRootDirectory()->isFile($this->getRootDirectory()->getRelativePath($filename));
    }
    return $this->_templatesValidationResults[$filename];
}

I changed it to

public function isValid($filename)
{
   return true;
}

Since I'm new to Magento, I don't understand what this method is supposed to be doing (I assume it's validating a template file, but I don't know how or where). Furthermore, when I added a log statement to the original code to show the contents of $this->_templatesValidationResults[$filename] (right before the return statement), it printed several empty array elements. For example, it printed

[] []  
[] []
[] []
[] []

It appears like Magento thinks the template files are invalid, but it doesn't give any reasons why they're invalid. Am I correct in saying this, and how would I either stop Magento from erroneously detecting the template files as invalid, or get the proper validation error message?

Possible Solution, and Further Questions

I traced the problem to the file magento\lib\internal\Magento\Framework\View\Element\Template\File\Validator.php

at the function

protected function isPathInDirectories($path, $directories)
{
    if (!is_array($directories)) {
        $directories = (array)$directories;
    }
    $realPath = $this->fileDriver->getRealPath($path);
    foreach ($directories as $directory) {
        if (0 === strpos($realPath, $directory)) {
            return true;
        }
    }
    return false;
}

The problem is that $path has forward slashes in it, but $realPath has backslashes, so the strpos never returns a match, and the function always returns false. I updated the function to

protected function isPathInDirectories($path, $directories)
{
    if (!is_array($directories)) {
        $directories = (array)$directories;
    }
    $realPath = $this->fileDriver->getRealPath($path);
    foreach ($directories as $directory) {
        if (0 === strpos($realPath, $directory) || 0 === strpos($path, $directory)) {
            return true;
        }
    }
    return false;
}

And now it works. I assume this is a Windows-only problem? Is this a bug in Magento that doesn't account for Windows file naming, or is there something I've done incorrectly in my setup?

Ben Rubin
  • 6,909
  • 7
  • 35
  • 82
  • 2
    You could find the solution for the symlink error but for the other one check this out https://stackoverflow.com/questions/53551878/blank-admin-page-on-magento-2-3-0-ce-in-localhost – revo Dec 01 '18 at 04:43
  • I did `php .\bin\magento setup:static-content:deploy -f` to try to solve the symlink error, and it looks like that did create the files that were missing. I followed the link you posted and the code that the user suggested to add was actually already in `validator.php`. The symlink error isn't occuring anymore in the log file, but I'm stilll getting the `invalid template file` errors. The file paths that the error lists do exist, so I'm not sure why it thinks there's a problem with the file. – Ben Rubin Dec 01 '18 at 20:09
  • Are you sure you don't have PHP caching enabled? e.g. opcache – revo Dec 01 '18 at 20:17
  • I think Magento is erroneously detecting my template files as invalid. I updated my original question to explain why. – Ben Rubin Dec 02 '18 at 14:43
  • See what data `$this->moduleDirs`, `$this->_themesDir` and `$this->_compiledDir` hold and what data `$filename` contains. – revo Dec 02 '18 at 17:41
  • `$filename` takes on many values. The first one is `C:/xampp/htdocs/magento23/app/code/Magento/Backend/view/adminhtml/templates/page/js/require_js.phtml`. The second one is the same path, with `translate.phtml` as the file name. There are many more values too. – Ben Rubin Dec 02 '18 at 22:06
  • $_themesDir is an associative array with keys `adminhtml/Magento/backend`, `frontend/Magento/blank`, and `frontend/Magento/luma` – Ben Rubin Dec 02 '18 at 22:09
  • `$_compiledDir` is `C:/xampp/htdocs/magento23/var/view_preprocessed/pub/static/` – Ben Rubin Dec 02 '18 at 22:10
  • `$moduleDirs` is an associative array with 143 entries, with keys such as `Magento_AdminNotification`, `Magento_AdvancedPricingImportExport`, `Magento_AdvancedSearch`, and so on. – Ben Rubin Dec 02 '18 at 22:11
  • I updated my question with a possible solution, and a further question about why my solution was necessary. – Ben Rubin Dec 02 '18 at 22:36
  • 1
    Oh, I see the link you sent me to at first actually already had a similar code change. I misread answer at the link when you sent it to me at first. – Ben Rubin Dec 02 '18 at 22:39
  • @BenRubin Did you install magento 2.3? If yes, can i get the installation docs? – Gem Dec 20 '18 at 05:56
  • @Gem Yeah I installed 2.3. There are installation instructions on Magento's website https://devdocs.magento.com/guides/v2.0/install-gde/prereq/zip_install.html – Ben Rubin Dec 20 '18 at 13:42
  • Okay, let me see, may I know how you give write permission to folder in Windows. As you know we need to give write permission to some folder, how you did that? – Gem Dec 20 '18 at 13:47
  • If you're doing this installation as an Admin user on windows, you can skip all that Linux permission stuff. I'm using Windows 10, and I skipped everything that had a Linux command. – Ben Rubin Dec 20 '18 at 14:01

1 Answers1

16

I have same issue to with magento 2.3 on Windows 10, backoffice page show blank page with brown background.

after searching the problem on the web, finally found solution

  1. open file /vendor/magento/framework/View/Element/Template/File/Validator.php in magento install dir , find

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

replace with :

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

Finally login page showing, but the icon is missing in login page and after login

  1. open file app/etc/di.xml in magento install dir, find

    Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink

and replace with

Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
  1. Then go to var/cache , delete all folder / file
  2. refresh the page, done.
pujionodk
  • 186
  • 1
  • 11
  • 4
    This solution is currently the way to hack core code to get 2.3 working in a windows environment BUT it will be reverted when you get a Magento update to whatever they have changed it to or back to the original. The current best practice is to use a form of virtual machine or vagrant like service with a linux guest operating system. This is not the quickest way but it is the best way to keep working without putting your workflow as risk in the future by hacking a fix into core code. – Mark Rees Jan 21 '19 at 21:00
  • All ok, but version folder not created (version file exist). How to solve this problem? – Raz Galstyan Jun 28 '19 at 16:50