DEV Community

Jack Huynh
Jack Huynh

Posted on • Edited on

Setup Magento2

Step 4: Download Magento

Before download Magento 2, we need Magento authentication keys to authenticate at Magento marketplace if don't have one.

Select My Account from the top-right corner. Now click Access Keys and Generate your new SECURE KEYS.

Public Key: Is your username
Private Key: Is your password
Enter fullscreen mode Exit fullscreen mode

Once you've acquired both the access keys, we can download Magento using one of 2 ways:

Through Github

You can download sourcecode https://github.com/magento/magento2/releases directly from Magento official repository

After donwloading, you should extract the pack to C:\xampp\htdocs\magento2 and run this command inside the folder.

Creating an authorization file

The Magento 2 GitHub repository requires you to authenticate. The composer install commands fails if you do not.

composer install
Enter fullscreen mode Exit fullscreen mode

After the process finished, run the command

composer config repositories.magento composer https://repo.magento.com/
Enter fullscreen mode Exit fullscreen mode

and

composer config http-basic.repo.magento.com <public key <private key>
Enter fullscreen mode Exit fullscreen mode

Through Composer

Go to C:\xampp\htdocs folder and run this command.

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
Enter fullscreen mode Exit fullscreen mode

After inserting your repo.magento.com username and password, it will ask for store credentials. Type β€œYes.”

Then Magento 2 will now start downloading on your server.

Image description


Regardless of the downloading method you choose, the final magento2 folder should look like this.

Image description

Step 5: Install Magento

Now every preparation steps are done and we can start installing Magento 2 on Localhost.

Go to C:\xampp\htdocs\magento2 folder, insert this command to start installing Magento 2 (make sure Elasticsearch, Apache, MySql all are running before execute this command)

php bin/magento setup:install --base-url="http://127.0.0.1/magento2/pub/" --db-host="127.0.0.1" --db-name="magento2" --db-user="root" --db-password="root" --admin-firstname="admin" --admin-lastname="admin" --admin-email="user@example.com" --admin-user="admin" --admin-password="Admin@123456" --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 --elasticsearch-enable-auth=1 --elasticsearch-username=elastic --elasticsearch-password=elastic
Enter fullscreen mode Exit fullscreen mode

Important options:

  • --base-url: your magento 2 installation folder
  • --db-name: your database name in step 4
  • --db-password: your database password in step 4

Others are optional, we can change later.

Image description

If you get the following error

In PatchApplier.php line 172:

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: Wrong file  

Enter fullscreen mode Exit fullscreen mode

Then follow this solution and run the command again

Image description

Now open the terminal and run these commands to upgrade the database

bin/magento indexer:reindex
bin/magento setup:upgrade
Enter fullscreen mode Exit fullscreen mode

Image description

and this command to compiles and generates optimized code for Dependency Injection

bin/magento setup:di:compile
Enter fullscreen mode Exit fullscreen mode

If you get the following error

In ErrorHandler.php line 62:

Warning: file_put_contents(C:/xampp/htdocs/magento2/generated/metadata/primary|global|plugin-list.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\magento2\lib\internal\Magento\Framework\Interception\PluginListGenerator.php on line 411   
Enter fullscreen mode Exit fullscreen mode

Then following this solution and run the command again

Image description

Now can start to deploying our static content

bin/magento setup:static-content:deploy -f
Enter fullscreen mode Exit fullscreen mode

Image description

Clear Cache

php bin/magento cache:flush
Enter fullscreen mode Exit fullscreen mode

Step 6: Install Sample Data

Now we will deploy sample data for our new Magento 2 website on localhost. Sample data will fill your website with some products, categories and images

Run these below commands

bin/magento sampledata:deploy
bin/magento indexer:reindex
bin/magento setup:upgrade
bin/magento setup:static-content:deploy -f
bin/magento cache:flush
Enter fullscreen mode Exit fullscreen mode

Well done! refresh your website and enjoy your new Magento 2.4 installation with sample data

Image description

Top comments (0)