How To Install Magento 2.4.2 On XAMPP
Magento 2.4.2 came out with a lot of improvements and useful features, especially a few tweaks to improve security. This makes it difficult to install on localhost. But after a period of research, we can install it successfully, follow the posts How to install Magento 2.4.2 On XAMPP to be able to do it.
1. Check Magento 2.4.2 System Requirement
First, you should check the system requirements of Magento 2.4.2 to choose compatible XAMPP and Elasticsearch versions.
You need to pay attention to the version requirements of Apache, MySQL, PHP, and Elasticsearch. Here, Magento 2.4 requires:
- Apache Version 2.4
- MySQL Version 8.0
- PHP Version 7.4
- Elasticsearch Version 7.9.x
Also, you should pay attention to a few required PHP extensions.
2. Download and Install XAMPP
Based on the requirements above, we proceed to select an appropriate XAMPP version. You can download XAMPP here.
We should choose the version of XAMPP that matches the above requirements. Then proceed to download and install.
3. Download Magento 2.4.2
Next, We download Magento 2.4.2-p1.
Unzip Magento 2.4.2-p1 to the XAMPP’s htdocs directory.
4. Download and Install Composer
After downloading Magento, we download and install Composer. You can access here to download Composer.
At the time of installation, choose the correct path to the php.exe of XAMPP just installed.
You can check if the Composer installation was successful or not by opening the Command Prompt with administrator privileges. Next, check with composer command.
5. Download and Install Elasticsearch
We downloaded Elasticsearch 7.9.3 into XAMPP’s htdocs directory and unzip it, you can use the latest version here.
Run elasticsearch.bat
as an administrator in the htdocs/elasticsearch-7.9.3/bin
directory.
You can check it at localhost with port 9200: localhost:9200
6. Configure extensions before installing
You open XAMPP Control Panel. Next, open php.ini in Apache’s config.
Find lines
;extension=intl
;extension=soap
;extension=sockets
;extension=sodium
;extension=xsl
replace to
extension=intl
extension=soap
extension=sockets
extension=sodium
extension=xsl
by removing the “;” in front of.
Expand memory_limit
to 4G:
Start Apache and MySQL in XAMPP Control Panel.
7. Fix Magento_Theme Error
To fix Module ‘Magento_Theme’ Error, go to xampp/htdocs/magento242/vendor/magento/framework/Image/Adapter/Gd2.php and replace the following function with the below 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;
}
8. Create a new database
Create a new database by access localhost/phpmyadmin/
. Next, select New, give the database a name and click Create.
9. Configure hosts file
Go to C:\Windows\System32\drivers\etc\hosts
and add the following line to the last row.
127.0.0.1 www.localhost.com
Note: You should run the editor tool as administrator to be able to confirm the change. |
10. Install Magento 2.4.2
Go to the folder containing the Magento 2.4.2 created earlier, and open cmd.
Enter the command to install:
php bin/magento setup:install --base-url="http://localhost/magento242/" --db-host="localhost" --db-name="magento242" --db-user="root" --admin-firstname="admin" --admin-lastname="admin" --admin-email="[email protected]" --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="localhost" --elasticsearch-port=9200
Note: edit base-url
, db-name
, admin-user
, admin-password
according to your configuration.
After the installation, will display like this:
11. Execute Additional Tweaks After Installed
Go to app\etc\di.xml
, search Symlink
and replace with Copy
.
Next, fix Magento 2 admin blank page. In vendor\magento\framework\View\Element\Template\File\Validator.php
, replace line 138 with:
$realPath = str_replace('\\', '/',$this->fileDriver->getRealPath($path));
Rename .htaccess
files in your Magento 2.4.2 folder.
Copy the index.php
and .htaccess
files from /pub/
folder.
And paste in Magento 2.4.2 root folder.
Open index.php
just copied in the Magento 2.4.2 root folder, find:
require __DIR__ . '/../app/bootstrap.php';
and replace with
require __DIR__ . '/app/bootstrap.php';
Go to the Magento 2.4.2 database on phpMyAdmin.
Run SQL queries on database:
INSERT INTO `core_config_data` (`config_id`, `scope`, `scope_id`, `path`, `value`, `updated_at`) VALUES (NULL, 'default', '0', 'web/secure/base_static_url', 'http://localhost/magento242/pub/static/', current_timestamp());
INSERT INTO `core_config_data` (`config_id`, `scope`, `scope_id`, `path`, `value`, `updated_at`) VALUES (NULL, 'default', '0', 'web/unsecure/base_static_url', 'http://localhost/magento242/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', 'http://localhost/magento242/pub/media/', current_timestamp());
INSERT INTO `core_config_data` (`config_id`, `scope`, `scope_id`, `path`, `value`, `updated_at`) VALUES (NULL, 'default', '0', 'web/unsecure/base_media_url', 'http://localhost/magento242/pub/media/', current_timestamp());
Note: Edit urls according to your base-url
|
After adding new rows successfully:
Finally, run step by step these commands:
php bin/magento indexer:reindex
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
If you have problems with the Admin Page: “Failed to send the message. Please contact the administrator”.
You need to disable the Two-Factor Authorization module using the following command:
php bin/magento module:disable Magento_TwoFactorAuth
So we have successfully installed Magento 2.4.2 on localhost. Here are the results:
This is How To Install Magento 2.4.2 On XAMPP.
Follow us for more helpful article!
We hope this is useful blog for you.
Thank you for reading!
in step 10, i got the error:
mysql server has gone away
please advise