How to Install and Configure Magento 2 Locally with XAMPP

Magento 2 is a very powerful e-commerce platform, but its server requirements are more complicated, especially the need to pass the Composer (which is a PHP Package Management SystemThis is not the default configuration on many platforms. If you want to set up a local development and testing environment, you can use XAMPP, a free and open source cross-platform web server solution.

图片[1]-如何在本地用 XAMPP 安装和配置 Magento 2

Benefits of running Magento 2 locally

There are many advantages to installing Magento 2 locally, including:

  1. save costs: No need to purchase a dedicated server.
  2. Offline Development: Web sites can be developed and tested without an Internet connection.
  3. safety test: Test new features or extensions without disrupting the production environment.
  4. custom development: All sorts of customizations can be made with confidence without causing the actual site to crash.
  5. Faster performance: Due to the absence of network latency, local environments are usually more responsive than remote servers.
  6. safety: Prevent unauthorized access and hacking.
  7. Easy Backup and Restore: Local sites can be quickly backed up and restored, reducing risk.

Local Installation Requirements for Magento 2

Before installing Magento 2, you need to ensure that the following components and system configurations are met:

  • Apache/NGINX version 2.2 or 2.4
  • PHP version 7.4.x or 8.1.x
  • MySQL/MariaDB Version 5.6.x, 5.7.x or Maria DB
  • Elasticsearch 7.6.x or later

Installing and setting up XAMPP

How to install Magento 2 locally.

Step: 1 Download the XAMPP server

Go to Apache Friends andDownload XAMPP ServerThe

此图片的 alt 属性为空;文件名为 20241128101333848-image.png

Magento strongly recommends installing XAMPP and PHP version 8.1.x for M2.4.5. Additionally, Magento 2.4 and PHP 7.3 can be installed, but are not tested or recommended.

Step: 2 Install XAMPP

After downloading XAMPP, double-click the file to install it on your computer.

click (using a mouse or other pointing device)the next stepButton.

此图片的 alt 属性为空;文件名为 20241128102125687-image.png

Retain the default selections in the diagram. Click thethe next stepButton.

此图片的 alt 属性为空;文件名为 20241128102216358-image.png

Select the installation folder. The default location isC:\xampp But it is recommended to choose according to your convenienceC:\A directory other than the drive, such asD:\maybeE:\ .

If you need to make changes, clickskim overicon to change the target location of the XAMPP program, and then click thethe next stepbutton to go to the next step.

此图片的 alt 属性为空;文件名为 20241128105236836-image.png

click (using a mouse or other pointing device)the next stepButton.

此图片的 alt 属性为空;文件名为 20241128105251121-image.png

click (using a mouse or other pointing device)the next stepButton.

此图片的 alt 属性为空;文件名为 20241128105306613-image.png

Wait for the installation wizard to install XAMPP on your computer.

此图片的 alt 属性为空;文件名为 20241128105355168-image.png

After the installation is complete, you will see the option "Should I start the control panel immediately? ". Keep it selected. Click the"Finish."Exit the installation and go toXAMPP Control PanelThe

此图片的 alt 属性为空;文件名为 20241128105453870-image.png

Step: 3 Configure PHP

In the XAMPP control panelIn theApachemobileconfigurebutton, and then click thePHP (php.ini)The

magento-xampp-安装-9

In php.iniIn the file, find the following lines and delete the semicolon before each line ::

;extension=intl

;extension=soap

;extension=sockets

;extension=sodium

;extension=xsl

;extension=gd

Expand memory_limit to 4G:

memory_limit=4G

When you are done, save and close the file. Then, click on the Apache and MySQL lines on the "commencement" button to start them. Don't quit XAMPP after this step, just let it run.

Step: 4 Configure the Hosts file

Access CatalogC:\Windows\System32\drivers\etc\hostsThe

此图片的 alt 属性为空;文件名为 20241128105732465-image.png

Add the following line to the last line:

127.0.0.1 www.localhost.com

此图片的 alt 属性为空;文件名为 20241128105834610-image.png

show (a ticket)XAMPP Control Paneland initiateApacherespond in singingMySQLApps.

此图片的 alt 属性为空;文件名为 20241128105852815-image.png

Creating a database in phpMyAdmin

Access URL http://localhost/phpmyadminTo create a database, enter the name of the database (e.g., Magento2) and click Create Database. Enter a database name (for example, Magento2) and click theestablishThe

此图片的 alt 属性为空;文件名为 20241128110916818-image.png

click (using a mouse or other pointing device)the next stepbutton to create a database.

magento 数据库

The database was created successfully.

magento-显示数据库

Attention:Remember the name of the database you want to create, as you will need to install Magento on it later.

Installing Composer for Magento

The latest version of Magento, Open Source 2.4.0 and above, is compatible with Composer 2. So, you need to install Composer 2 to download the latest version of Magento 2.

The best way to do this is to download and runComposer-Setup.exeThis will install the latest version and set up a new version from any directory. This will install the latest version and setup from any directory "The path to the "Composer" call.

此图片的 alt 属性为空;文件名为 20241128111117691-image.png

click (using a mouse or other pointing device)the next stepbutton and browse for the PHP path in the XAMPP folder.

此图片的 alt 属性为空;文件名为 20241128111147995-image.png

Optionally, you can enter a proxy URL.

此图片的 alt 属性为空;文件名为 20241128111214428-image.png

click (using a mouse or other pointing device)"Installation"button for the final step.

此图片的 alt 属性为空;文件名为 20241128111240567-image.png

click (using a mouse or other pointing device)the next stepButton.

此图片的 alt 属性为空;文件名为 20241128111257805-image.png

click (using a mouse or other pointing device)fulfillmentButton.

此图片的 alt 属性为空;文件名为 20241128111313559-image.png

activate (a plan)command prompt (computing)and run the Composer command to verify that it is installed without any problems.

此图片的 alt 属性为空;文件名为 20241128111337905-image.png

Downloading Magento with Composer

Next, cd toC:\xampp\htdocsand use Composer to run the following command to download a specific Magento 2 version.

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.5

Magento Open Source

composer create-project --repository-url=https://repo.magento.com/magento/project-community-edition:2.4.5

Adobe Commerce (Enterprise Edition)

composer create-project --repository-url=https://repo.magento.com/magento/project-enterprise-edition:2.4.5

With the above command, you can specify the specific version of Magento (2.0, 2.1, 2.2.1, 2.2.2, 2.2.3, 2.2.4, 2.2.5, 2.2.6, 2.3, 2.4). If not, skip the version and run the following line directly:

此图片的 alt 属性为空;文件名为 20241128142858794-image.png

Next, enter your Magento authentication key.public keyrespond in singingThe private key is in theMagento Marketplace AccountCreate and configure it in the Locate the account name in the upper right corner of the page and select theMy ProfileThe

此图片的 alt 属性为空;文件名为 20241128142955410-image.png

Next, click"The market."tab of theaccess keyThe

magento-访问密钥

click (using a mouse or other pointing device)"Create new access key".Enter a specific name for the key (e.g., the name of the developer receiving the key) and click "recognize".

magento-keys

Copy the user name in thepublic keyand in the passwordprivate key to install Magento.

magento-keys-enter
magento-key-enter-2

The writer takes a while to download and install all the necessary modules. Once it's all done, you can see these below:

magento-成功下载

Installing Elasticsearch for Magento 2

Elasticsearch is the recommended extension for Magento version 2.4.X.

Download Elasticsearch 7.6.0:https://www.elastic.co/downloads/past-releases/elasticsearch-7-6-0(Magento 2.4.x has only been tested with Elasticsearch 7.6.x. Other 7.x versions can be used at your discretion, but a tested version of Elasticsearch is recommended.)

Extract the .zip file you just downloaded. In a terminal window, go to the extracted directory and run the following command:

. \bin\elasticsearch.bat

Also check port 9200Availability of Elasticsearch on the Web. In your browser, typelocal:9200The following is a summary of the installed Elasticsearch extensions.

{"name" : "DESKTOP-Jyoti", "cluster_name" : "elasticsearch", "cluster_uuid" : "ONNrUlTWQCSoigYBy6WF9g", "version" : {"number" : "7.9.3", "build_ flavor" : "default", "build_type" : "zip", "build_hash" : "c41E4fgiueQSoiytrBW", "build_date" : "2023-02-02T09:51:41.449Z", "build_snapshot" : false, "lucene_version" : "8.7.0", "minimum_wire_compatibility_version" : "6.8.3", "minimum_index_compatibility_version" : "6.8.3"}," tagline" : "You Know, for Search"}

Install Magento 2 with the command

Open a command prompt window. Next, go to the Magento directory and execute the following command:

php bin/magento setup:install --base-url="http://localhost/magento2/" --db-host="localhost" --db-name="dbmagento241" --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

Please note:Assign the base URL according to the path, and write downAdministrator User Namerespond in singingcryptographicfurthermorerefrain fromUse the Elasticsearch port.

Replace these values:

  • -base-url: magento 2 installation folder
  • -db-name ::Database name when creating the database
  • -db-password:Database Password
  • -db-user:Database user with full privileges. The default root user is usually used.
  • -db-password:The password for the database user. If you use the "root"Database user, leave it blank
  • -admin-firstname:Administrator Name
  • -admin-lastname:Administrator's last name
  • -admin-email:Administrator e-mail address
  • -admin-user:The username used to log in to the admin panel
  • -admin-password:Password for logging into the admin panel
  • -language:The language used in the admin panel and storefront. Use the language code, e.g. en_US.
  • -admin-email.Change this to the website's email
  • -currency:Set the default currency used by the store. Type php bin/magento info:currency:list to get a list of supported currencies and their code
  • -timezone:Change the time zone in which you are located. (e.g. Beijing time, etc.)
  • -url-rewrites:Set to 1 to enable web server rewriting. This will help improve your site ranking.
  • -backend-frontname:Set the site administration URL. omitting this parameter will result in a randomly generated URL for the Magento administration path (e.g. admin_jkhgdfq)
  • -search-engine:Sets the version of Elasticsearch to use for this Magento installation. The default is elasticsearch7
  • -elasticsearch-host: The hostname or IP address where Elasticsearch is running. The default is localhost
  • -elasticsearch-port: The port number on which Elasticsearch listens. The default is 9200.

The other values are optional and you can change them later.

Now, if all goes well, Composer 2 will start installing Magento 2. This process will take about 10 minutes.

此图片的 alt 属性为空;文件名为 20241128143910785-image.png

Just be patient, as it will take some time to install all the instances and setup the modules required for Magento 2.4.5.

After installing, get these:

此图片的 alt 属性为空;文件名为 20241128144016757-image.png

Run command

Now, the following command needs to be run.

php bin/magento indexer:reindexphp bin/magento setup:upgradephp bin/magento setup:static-content:deploy -fphp bin/magento cache:flush

Now click on the URL (usuallylocalhost/magento2/pub/) or the base URL set for base-url during installation.

For administrators: use http://localhost/magento2/pub/admin访问管理后台网址.

summarize

With the steps in this article, you can easily set up a Magento 2 environment locally for development and testing. We hope this tutorial will help you to successfully install and run Magento 2. If you encounter any problems, feel free to contact us atCommunities of exchangeLeave a message for help!


Contact Us
Can't read the tutorial? Contact us for a free answer! Free help for personal, small business sites!
客服微信
Customer Service
Tel: 020-2206-9892
QQ咨询:1025174874
(iii) E-mail: [email protected]
Working hours: Monday to Friday, 9:30-18:30, holidays off
© Reprint statement
This article was written by Banner1
THE END
If you like it, support it.
kudos373 share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments