Install Magento 2.4 on Windows 10 (2021)
Installing Magento 2.4 on Windows 10 can be really frustrating because of all the errors related to configurations. Here is a very simple step by step tutorial to install Magento 2.4, configuring and resolving all the errors that arise in the process. A video-based tutorial is also available if you prefer to watch and follow the steps.
Following are the pre-requisites required for installing Magento. Download the setups of the following.
- XAMPP (PHP ≥ 7.3)
- Composer
- Elasticsearch
- Magento (Version 2.4.1 without sample data)
After downloading the setups, You need to install XAMPP and Composer and follow the steps below.
- Start Apache and MySQL from XAMPP Control Panel.
- Navigate to htdocs folder inside XAMPP installation directory.
- Create a new folder inside htdocs with the name of “elasticsearch”. Paste the downloaded Elasticsearch zip file inside the newly created folder. Extract the zip file, navigate to bin folder, and double click on “elasticsearch.bat” to start elasticsearch cluster.
- Make sure that elasticsearch is up and running by visiting localhost:9200 by any browser. You should see a JSON object.
- Now visit localhost/phpmyadmin and create a new database ‘magento’
- Create a new folder inside htdocs with the name of ‘magento’. Paste the Magento zip file, that we downloaded earlier, inside this folder and extract it.
- Inside your magento directory, navigate to vendor\magento\framework\Image\Adapter and open G2d.php with any code editor. Search for the method named “validateURLScheme”, which should be at line # 86. Replace the entire method code with this code:
private function validateURLScheme(string $filename) : bool
{
$allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
$url = parse_url($filename);
if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename))
{
return false;
}
return true;
}
- Inside your magento directory, navigate to vendor\magento\framework\View\Element\Template\File and open Validator.php with any code editor. Scroll down to line # 138. Replace the entire line with the following snippet:
$realPath = str_replace('\\', '/',$this->fileDriver->getRealPath($path));
- Inside your magento directory, navigate to vendor\magento\framework\Interception and open PluginListGenerator.php with any code editor. Scroll down to line # 158. Replace the entire line with the following snippet:
$cacheId = implode(‘-’, $this->scopePriorityScheme) . “-” . $this->cacheId;
- Inside your XAMPP installation directory, navigate to xampp/php and open php.ini with any code editor. Enable the extensions intl, soap, sockets, xsl on line 921, 943, 944, 949 respectively by removing semi-colon before the word extension. Now restart xampp.
- Inside your magento directory, open cmd and run the following commands in order. If any command gives an error, make sure your PHP version is 7.3 or greater and you’ve made all the changes mentioned above.
php bin/magento setup:install --base-url=”http://localhost/magento" --db-host=”localhost” --db-name=”magento" --db-user=”root” --db-password=”” --admin-firstname=”admin” --admin-lastname=”admin” --admin-email=”user@example.com” --admin-user=”admin” --admin-password=”admin123" --use-rewrites=”1" --backend-frontname=”admin” php bin/magento setup:di:compile php bin/magento indexer:reindex php bin/magento setup:upgrade php bin/magento setup:static-content:deploy –f php bin/magento deploy:mode:set developer php bin/magento cache:clean php bin/magento cache:flush php bin/magento module:disable Magento_Csp php bin/magento module:disable Magento_TwoFactorAuth
- We are nearly there. Open localhost/phpmyadmin and switch to database ‘magento’. Now the run the following query in the SQL Query tab:
INSERT INTO `core_config_data`(`path`, `value`) VALUES (‘dev/static/sign’, 0) ON DUPLICATE KEY UPDATE `value`=0
- Open localhost/magento/admin in any browser and login using ‘admin’ and ‘admin123’ as username and password respectively. After logging in, if the loader does not disappear and keeps on loading then there is one more change you need to make. Inside your magento directory, navigate to app/etc/di.xml and search for
Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink
and replace it with
Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
- Now refresh the page and voila, you have installed Magento 2.4 successfully! Phew, that was a lot of work.
If you got stuck at any point, there is a video tutorial available and you can watch it for a reference.