The blank admin page issue in Magento 2 often occurs when you upgrade Magento 2 version or even with a fresh installation of Magento 2 in Localhost.
Note: You may not see this error on a live site hosted on Magento 2 hosting server, the fix for live site is different. Drop a comment below if you see this error on live site.
When this error occurs, you will see Magento 2 admin page like this.
A proper admin page of Magento 2 should be like this
I have been facing this issue many times and I finally understand why this error happens. I also found a method working to fix this annoying Magento 2 issue.
Contents
Cause of the error
The error usually happens on a localhost installation of Magento 2 on the Windows operating system. The cause of this error is that Magento 2 and Windows has a different file path indicator.
- On Windows, you can see path to a folder like this:
C://Magento2/App/Code
- In Magento 2, file path is:
Magento2\App\Code
That’s it! The cause of the error is different file path indicators between Magento 2 and Windows, which make Magento 2 couldn’t load template files.
Solution
This error usually occurs in Magento 2.2.7 and Magento 2.3, 2.3.1, 2.3.2, 2.3.3 version.
As the 2 versions 2.3.x and 2.2.7 have some differences in code, there should be 2 fixes for each version.
Solution for Magento 2.3.x
Go to Validator.php template file located in your theme’s folder: C:\\xampp\htdocs\magento2_installation_folder\vendor\magento\framework\View\Element\Template\File\Validator.php
If you can’t find \vendor\magento\framework\
folder, go check in
C:\xampp\htdocs\magento\lib\internal\Magento\Framework\View\Element\Template\File\Validator.php
Next, go to line 138-139 you will see this code
$realPath = $this->fileDriver->getRealPath($path);
This line of code defines the admin template file path, we will update this line to fix the issue. Now replace this line with the following code:
$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
You can either remove the old code or better, comment that code line by putting “//” in front of the old code line. The new code should be like this:
I highlighted the line here:
/** * Checks whether path related to the directory * * @param string $path * @param string|array $directories * @return bool */ protected function isPathInDirectories($path, $directories) { if (!is_array($directories)) { $directories = (array)$directories; }
//$realPath = $this->fileDriver->getRealPath($path);
$realPath = str_replace(‘\\’, ‘/’, $this->fileDriver->getRealPath($path));
foreach ($directories as $directory) { if (0 === strpos($realPath, $directory)) { return true; } } return false; }
Now save file and refresh Magento 2 admin page to see if the issue is fixed
Solution for Magento 2.2.7
The older version – Magento 2.2.7 – has a little different fix.
We will add $realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
before if (!is_array($directories)) {
Also, we will change if (0 === strpos($this->fileDriver->getRealPath($path), $directory)) {
to if (0 === strpos($realPath, $directory)) {
Now the new code should be like this:
Now save changes and refresh your website to see if the blank admin page issue is fixed
How to fix Magento 2 admin page keep loading
Sometimes after fixing the blank admin page issue, you may experience admin page keep loading. You can’t do anything with the loading admin page, even reload the page does not help.
The issue should be like this:
Cause of the error
This error happens because Magento 2 didn’t finish deploying static view files in production mode.
Static view files are can be found in the <magento_root>/pub/static
, and some files are cached in the <magento_root>/var/view_preprocessed
directory.
Solution
To fix this error, we will run a command that forces Magento 2 to deploy static view files
To open CLI interface in Windows, go to your Xampp control panel and click on Shell button.
Run the following command in Shell interface:
php bin/magento setup:static-content:deploy -f
Wait a few seconds for Magento 2 system to deploy static content.
Sample output:
Now refresh Magento 2 admin page and the issue should be fixed
Video tutorial on how to fix admin blank page in Magento 2
If you follow all the steps in my tutorial but still not get the issue fixed then follow this video tutorial.
Wrapping up
Magento 2 is complex and sometimes, errors may not occur in Live environment, but do occur in local environment. It’s crucial to understand the cause of the issues so that we can fix the issues the next time we face them.
I hope this tutorial helps you fix the issue: Blank Magento 2 admin page in local and Magento 2 page keep loading.
If you followed my tutorial but the issue still persists, drop a comment below and I will be happy to help.