Tutorial: How to install Magento 2.4.7 community edition on localhost, Windows OS, XAMPP (php8.2 version).
If you install a fresh Magento 2.4.7 on localhost, you may encounter errors that make the installation incomplete.
Common errors
Unable to apply data patch Magento\Theme\Setup\Patch\Data\RegisterThemes for module Magento_Theme. Original exception message: Wrong file
In Gd2.php line 70:
Css and website layout broken
Missing image files
Prepare to Install
Firstly, you need to download mgento-2.4.7 by using the command line:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.7 magento-2.4.7
Files need to be modified for localhost
1. Change the Validator.php in vonder\magento\framework\View\Element\Template\File at line 138, that's isPathInDirectories function
Orginal scripts:
$realPath = $this->fileDriver->getRealPath($path);
Change to:
$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
2. Find validateURLScheme function in vendor\magento\framework\Image\Adapter\Gd2.php file. at line 96.
Orginal scripts:
if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes)) {
return false;
}
Change to:
if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename)) {
return false;
}
3. Disable the modules: Magento_AdminAdobeImsTwoFactorAuth Magento_TwoFactorAuth
Installation
Run command line to install Magento project
php bin/magento setup:install --base-url="https://site.local/magento-2.4.7/" --db-host="localhost" --db-name="magento_247" --db-user="root" --admin-firstname="admin" --admin-lastname="admin" --admin-email="admin@example.com" --admin-user="admin" --admin-password="admin123" --language="en_US" --currency="USD" --timezone="America/Chicago" --use-rewrites="1" --backend-frontname="admin" --search-engine=elasticsearch7 --elasticsearch-host="127.0.0.1" --elasticsearch-port=9200
After the installation command line is done, please run SQL Query below:
INSERT INTO `core_config_data` (`config_id`, `scope`, `scope_id`, `path`, `value`, `updated_at`) VALUES (NULL, 'default', '0', 'web/secure/base_static_url', 'https://site.local/magento-2.4.7/pub/static/', current_timestamp()), (NULL, 'default', '0', 'web/unsecure/base_static_url', 'https://site.local/magento-2.4.7/pub/static/', current_timestamp());
INSERT INTO `core_config_data` (`config_id`, `scope`, `scope_id`, `path`, `value`, `updated_at`) VALUES (NULL, 'default', '0', 'web/secure/base_media_url', 'https://site.local/magento-2.4.7/pub/media/', current_timestamp()), (NULL, 'default', '0', 'web/unsecure/base_media_url', 'https://site.local/magento-2.4.7/pub/media/', current_timestamp());
Move index.php, cron.php, get.php, static.php and .htaccess from /pub/ to the root web (magento-2.4.7)
Change index.php at line 12
require __DIR__ . '/../app/bootstrap.php';
to
require __DIR__ . '/app/bootstrap.php';
If the website does not work because of CSS issues, you can fix it by following these steps:
php bin/magento config:set dev/static/sign 0
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f