How To Install Magento 2 on Localhost in 5 Easy Steps

How To Install Magento 2 on Localhost in 5 Easy Steps

Are you a developer looking to install Magento 2 for your online store? This tutorial will walk you through the procedures to set up Magento, ensuring a smooth and successful installation. It will equip you with the knowledge and skills necessary to ensure the smooth operation of your online store.

Best Magento Hosting now

Key Takeaways

  • Learn how to install Magento step-by-step to ensure your online store's successful setup.

  • Gain insight into the Magento installation methods, which entails preparing your server, downloading the required software, and effectively unpacking it.

  • Learn database creation on your hosting platform and utilize the installation wizard to establish Magento seamlessly.

  • Explore troubleshooting strategies to resolve issues while working with Magento.

What is Magento?

Magento is an ecommerce platform built on open-source technology. It empowers online sellers with a versatile shopping cart system and complete control over their store's appearance, content, and features. It offers search engine optimization and catalog management capabilities. It also provides cutting-edge marketing solutions, including customized promos and targeted campaigns.

5 Easy Steps to Install Magento 2

Follow these five simple steps to install Magento using XAMPP:

1. Download and Install XAMPP

XAMPP download and installation screen

Before you install Magento, it's crucial to set up XAMPP. Here's a step-by-step guide for that:

Install XAMPP on your windows. It is a software package that includes PHP and MySQL, both essential for running Magento. Follow these steps:

  1. Download XAMPP from the official website.

  2. Install XAMPP.

  3. Start Apache and MySQL services using the XAMPP control panel.

2. Download Magento

Begin by obtaining the Magento installation files:

  1. Visit the official Magento website or Download it from other sources.

  2. Select the Magento version that best fits your project's requirements. It can be Magento Project Community Edition, Enterprise Edition, or another variant.

  3. Download the chosen file to your computer.

  4. Extract or unzip this downloaded file to c:\xampp\htdocs\magento2.

  5. Start the Installation Setup of Magento 2 by running localhost open project – localhost/magento2.

Magento installation setup screen

  1. Check your server's PHP installation, configuration, installed extensions, and file permissions by clicking the Start Readiness Check button.

Magento start readiness check interface

Note: You will need to fix any displayed issues before proceeding. To view additional details about each check, click More detail (if applicable).

Fixing issues displayed during Magento installation

3. Set Up Your Database

To ensure your Magento installation proceeds seamlessly, follow these steps to create and configure a database on your hosting platform:

  1. Select a unique username and set a secure password (you'll need these credentials later). Click Next.

Adding a new database for Magento installation

  1. In Web Configuration, simply enter the store and magento admin address. Then click Next.

Web configuration step during Magento database setup

4. Customize Your Store

  1. Customize default settings such as currency (USD), timezone (America), and language (English) to suit your preferences.

Customizing default store settings in Magento

  1. Before installing Magento, you can expand the Advanced Modules Configuration to enable or disable modules as needed.

Advanced Modules Configuration during Magento setup

  1. After selecting your modules, click Next.

5. Install Magento

  1. Create admin account.

Creating an admin account for Magento

  1. Set the username, email, and password. Click Next.

  2. After you provide the required information, click Install Now to begin the installation process.

Finalizing Magento installation process

  1. After successful installation, log in to your Magento admin panel to customize your store further.

Advanced Methods for Installing Magento 2

You can also install Magento in several other ways:

Method 1: Using Composer


1. Pre-Installation

Before proceeding, check that you have configured the server, created the Magento file system owner, and set up a Magento cron job for command line execution.

After that, install the composer and finish the prerequisites.

Note: You will need the authentication keys in your Magento account.


2. Log in as the file system owner

Become the file system owner by logging into Magento or changing to a writable user.

If you are using the bash shell, use the following directive to change to the Magento file system owner and enter the command at the same time:

su <Magento file system owner> -s /bin/bash -c <command>

Adding magento_root>/bin to your PATH variable will allow you to execute Magento commands from anywhere. Below is an example of the CentOS bash shell:

export PATH=$PATH:/var/www/html/magento2/bin

3. Get the Setup

Here’s what you need to get the Magento meta-package:

  1. Log in or switch to Magento file system owner on your server.

  2. Enter the web server's docroot or the virtual host's docroot.

  3. Command to create a Composer project with Magento Commerce or Magento Open Source meta-package:

For Commerce:

composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition <install-directory-name>

For Open Source:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition <install-directory-name>

Once prompted, you will need to provide the authentication keys.

The setup wizard will complete the installation process once you have completed all these steps.

Method 2: Using GitHub

Installing Magento without sample data:

  1. Clone the Magento repository from GitHub. You can check out the previous Magento releases.

  2. Using the following command, create a new empty directory:

git clone git@github.com:magento/magento2.git
  1. Wait until the deployment finishes and then execute this command.
composer install
  1. Install Magento

Below is a provided example of the command to install Magento 2.

Note: Modify the base-url, db-name, db-password, admin-email, and admin-password. They need to be appropriate for your local setup.

php -f bin/magento setup:install -base-url=http://m2.loc/2.07/github/ --backend-frontname=admin --db-host=localhost --db-name=m2git --db-user=root --db-password=inchoo --admin-firstname=Magento --admin-lastname=User --admin-email=ivan.veres@inchoo.net --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago -use-rewrites=1
  1. Open a browser window and go to your local URL.

Method 3 Using sample data:

  1. Go to your webroot (not magento).

  2. Run this command to clone the Magento directory:

git clone git@github.com:magento/magento2-sample-data.git
  1. Go to the cloned directory.

  2. Run this command:

php -f dev/tools/build-sample-data.php -- --ce-source="your Magento CE install dir"

This creates Symlinks to the Magento installation.

  1. Set ownership and permissions on your Linux machine:
chown -R :your web server group name
find . -type d -exec chmod g+ws {} \;
  1. Now go to Magento var/ folder to clear the cache (static files) by running the following command:
rm -rf cache/* page_cache/* generation/*
  1. Finally, run these commands to install sample data:
php bin/magento setup:upgrade
php bin/magento setup:di:compile

If you encounter any issues during installation, contact Adobe Commerce Support for assistance.

Troubleshooting Tips

Here are some troubleshooting tips to help you if you encounter any issues during Magento Installation:

1. Create User Via CLI

You can execute it by running the following command in CLI:

php bin/magento admin:user:create --admin-user=admin --admin-password=admin123 --admin-email=admin@example.com --admin-firstname=admin --admin-lastname=user

This command let's you create a new user.

2. Check Web Configuration

Verify that your web configuration meets the system requirements for running Magento. Ensure that you have properly configured PHP, MySQL, and other required components.

3. Version Compatibility

Confirm you've downloaded the correct Magento version. If needed, consider upgrading Magento to the latest compatible release.

4. Database Setup

Double-check your database setup to align with your hosting provider's configurations. Verify database credentials and permissions.

5. File Uploads

Ensure you've successfully uploaded and unpacked all the necessary Magento files. Pay attention to directory structures.

6. Accuracy in Setup

During the Magento setup process, provide accurate information, including your store's base URL, admin path, and currency settings. Following these troubleshooting steps, you can address common installation issues and ensure a successful Magento setup for your online store.

If you're still having problems after trying the troubleshooting steps, contact Adobe Commerce Support.

FAQs

1. How much does Magento cost?

The license fee for Magento Commerce depends on your company's size and online revenue, while Magento Open Source is free.


2. How do I install Magento Store on my web server?

To establish a Magento Store on your web server, follow these steps:

  • Create a project file using Composer by composer create-project.
  • Ensure you have an authentication key from Magento.
  • Utilize the php bin magento setup tool to install Magento in your server's root directory.
  • Grant root access and configure the necessary file permissions for the Magento installation directory.

3. What are the server requirements for Magento?

Magento requires a LAMP or LNMP stack, PHP 7.3 or later, MySQL 5.6 or later, and a secure HTTPS connection.


4. How can I update and download Magento?

You can update and download Magento using the Web Setup Wizard, command line, or Composer.


5. What do I need for the deployment configuration process?

For deployment, you need details like the database user, database password, db host, localhost db, and admin URL. Ensure you have these before starting with the deployment configuration enable commands.


6. Is there any use of Magento commands after the initial setup?

Yes, command line tools can add components, disable Modules, and fix functionality and security after installing Magento.


7. How can I set file permissions on the web server for the installation of Magento?

Before installing Magento, make sure the web server group has read/write access to the directory. You can run the following command to do so:

cd /var/www/html/<magento install directory>
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R :www-data . # Ubuntu
chmod u+x bin/magento 

Summary

It is crucial to install Magento to establish a solid foundation for your online store's success. This detailed tutorial covers step-by-step setup and troubleshooting to make Magento installation easy.

Ready to launch your Magento store? Explore Magento hosting plans to unlock your e-commerce’s full potential.

Magento Hosting Free Demo on AWS

Maria Ajnawala
Maria Ajnawala
Technical Writer

Maria has over five years of expertise in content marketing, specialising in Magento insights and industry trends. She excels in creating engaging content that resonates within the Magento community.


Get the fastest Magento Hosting! Get Started