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.

Magento 2.4.2 system requirements

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.

Choose XAMPP version conforms with Magento 2.4.2

We should choose the version of XAMPP that matches the above requirements. Then proceed to download and install.

Install XAMPP

3. Download Magento 2.4.2

Next, We download Magento 2.4.2-p1.

Download Magento 2.4.2-p1

Unzip Magento 2.4.2-p1 to the XAMPP’s htdocs directory.

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.

Download Composer

At the time of installation, choose the correct path to the php.exe of XAMPP just installed.

Composer choose path of XAMPP

You can check if the Composer installation was successful or not by opening the Command Prompt with administrator privileges. Next, check with composer command.

Check Composer

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.

Download Elasticsearch 7.9.3 and unzip

Run elasticsearch.bat as an administrator in the htdocs/elasticsearch-7.9.3/bin directory.

Run as administrator elasticsearch.bat
Run elasticsearch 7.9.3

You can check it at localhost with port 9200: localhost:9200

Check elasticsearch 7.9.3 on 9200 port

6. Configure extensions before installing

You open XAMPP Control Panel. Next, open php.ini in Apache’s config.

Open 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.

Edit php.ini  php extensions

Expand memory_limit to 4G:

Expand memory_limit to 4G

Start Apache and MySQL in XAMPP Control Panel.

Restart XAMPP

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;
 }
Fix Magento_Theme Error In Magento 2.4.2

8. Create a new database

Create a new database by access localhost/phpmyadmin/. Next, select New, give the database a name and click Create.

Create magento242 database

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.
Configure hosts file

10. Install Magento 2.4.2

Go to the folder containing the Magento 2.4.2 created earlier, and open cmd.

Go to the magento 2.4.2 folder 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-urldb-name, admin-useradmin-password according to your configuration.

Install Magento 2.4.2

After the installation, will display like this:

Install Magento 2.4.2 Successfully

11. Execute Additional Tweaks After Installed

Go to app\etc\di.xml, search Symlink and replace with Copy.

Search Symlink in di.xml
Replace Symlink with Copy in di.xml

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));
Fix magento 2.4.2 admin blank page

Rename .htaccess files in your Magento 2.4.2 folder.

Rename  .htaccess files in your Magento 2.4.2 folder

Copy the index.php and .htaccess files from /pub/ folder.

Copy the index.php and .htaccess files from pub folder

And paste in Magento 2.4.2 root 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';
Replace bootstrap require dir

Go to the Magento 2.4.2 database on phpMyAdmin.

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
Run SQL queries on database

After adding new rows successfully:

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”.

Two-Factor Authorization Error

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:

Magento 2.4.2 Storefront
Magento 2.4.2 Admin Panel

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!

4.9 7 votes
Article Rating

Aaron LX

Aaron is a passionate writer, crazy about shopping, eCommerce and trends. Besides his outstanding research skills and a positive mind, Aaron eagerly shares his experience with the readers.

Leave a Reply or put your Question here

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Ca Tca
Ca Tca
April 22, 2022 9:06 am

in step 10, i got the error:
mysql server has gone away

please advise

1
0
Would love your thoughts, please comment.x
()
x