Resolving Magento Admin Black Screen Issue
If you are encountering a black screen issue in the Magento admin panel, it might be due to a path handling problem. A simple change in the isPathInDirectories
function can help resolve this issue. Follow the steps below to implement the solution.
Step-by-Step Guide:
- Locate the Function:
Find the
isPathInDirectories
function in your Magento codebase. It should look something like this:protected function isPathInDirectories($path, $directories) { if (!is_array($directories)) { $directories = (array)$directories; } $realPath = $this->fileDriver->getRealPath($path); foreach ($directories as $directory) { if ($directory !== null && 0 === strpos($realPath, $directory)) { return true; } } return false; }
- Modify the Code:
Replace the line:
$realPath = $this->fileDriver->getRealPath($path);
$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
protected function isPathInDirectories($path, $directories) { if (!is_array($directories)) { $directories = (array)$directories; } $realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path)); foreach ($directories as $directory) { if ($directory !== null && 0 === strpos($realPath, $directory)) { return true; } } return false; }
- Save and Test: Save the changes and refresh your Magento admin panel. The black screen issue should now be resolved.
Explanation:
The problem arises because paths with backslashes (\
) might not be recognized correctly, especially in environments where forward slashes (/
) are expected. By replacing backslashes with forward slashes, the paths are normalized, ensuring they are handled correctly across different systems.