Magento 2 Installation on macOS

Magento 2 Installation on macOS

Magento 2 is a powerful and popular open-source e-commerce platform that allows you to create and manage online stores. Magento 2 offers many features and functionalities, such as product catalog management, shopping cart, checkout, payment, shipping, marketing, customer service, analytics and more. Magento 2 also supports multiple languages, currencies, stores and websites.

In this tutorial, we will show you how to install Magento 2 on a macOS system using MAMP. MAMP is a free and easy-to-use solution that provides Apache, MySQL and PHP on your Mac. We will also install and configure some additional components and tools that are required or recommended for Magento 2, such as Composer, Elasticsearch and Redis.

Before you begin, make sure that you have a Mac with macOS Catalina 10.15 or later and at least 8 GB of RAM. You will also need a domain name pointing to your Mac’s IP address or a local domain name using hosts file.

Step 1: Install MAMP

MAMP is the most popular local web development solution for Mac. It is free and includes Apache or Nginx, PHP or Python, Perl or Ruby. To download the latest version of MAMP, go to https://www.mamp.info/en/downloads/ and click on the Download button.

Open and install MAMP application for your Mac by following the instructions on the screen. After the installation is complete, open MAMP in MAMP application folder.

To configure MAMP settings, click on Preferences in the main window. In the Preferences dialog box, do the following:

  • Click on Ports tab and set Apache Port to 80 and MySQL Port to 3306. This will allow you to access your local web server using http://localhost/ or your domain name without specifying a port number.
  • Click on Web Server tab and select Apache as your web server. Then click on Select next to Document Root and choose a folder where you want to store your web files. For example, you can create a folder named htdocs in your home directory and select it as your document root.
  • Click on PHP tab and select PHP 7.4.0 as your PHP version. This is the minimum PHP version required by Magento 2.
  • Click on OK to save your settings and close the Preferences dialog box.

To start MAMP services, click on Start Servers in the main window. You should see green indicators next to Apache Server and MySQL Server.

To check if MAMP is working, open your web browser and go to http://localhost/. You should see a MAMP welcome page like this:

 

Step 2: Install Composer

Composer is a dependency manager for PHP that can help you install and update Magento components and their dependencies. Magento 2 requires Composer 1.x or later.

To install Composer for Magento, open Terminal app on your Mac and run the following command:

curl -sS https://getcomposer.org/installer | php

This will download and install Composer as a file named composer.phar in your current directory.

To make Composer globally accessible, move it to a directory that is in your system PATH, such as /usr/local/bin. For example:

sudo mv composer.phar /usr/local/bin/composer

To check if Composer is installed and working, run the following command:

composer --version

You should see an output similar to this:

Composer version 2.1.14 2021-11-30 10:51:43

To use Composer to install and update Magento components, you will need to obtain authentication keys for the Magento code repository. You can get these keys from your Magento Marketplace account or create a new account if you don’t have one.

To get your authentication keys, follow these steps:

  • Log in to your Magento Marketplace account or create a new one at https://marketplace.magento.com/.
  • Click on your profile icon in the top-right corner and select My Profile.
  • Click on Access Keys in the left sidebar.
  • Click on Create A New Access Key and enter a name for your key pair.
  • Click on Generate New to create your public and private keys.
  • Copy and save your keys somewhere secure. You will need them later when you use Composer.

You have successfully installed Composer and obtained your authentication keys for Magento.

Step 3: Install Elasticsearch and Redis for Magento

The third step is to install Elasticsearch and Redis for Magento. Elasticsearch is a distributed, RESTful search and analytics engine that provides fast and advanced searches on products in the catalog. Redis is an in-memory data structure store that can be used as a cache backend for Magento.

To install Elasticsearch and Redis for Magento, open Terminal app on your Mac and run the following commands:

To install Elasticsearch using Homebrew, run the following command:

brew install elasticsearch

To start Elasticsearch as a service, run the following command:

brew services start elasticsearch

To check if Elasticsearch is running, run the following command:

curl http://localhost:9200

You should see an output similar to this:

{
  "name" : "MacBook-Pro.local",
  "cluster_name" : "elasticsearch_brew",
  "cluster_uuid" : "QoY6fD7sQZq1l9fX8y0z9g",
  "version" : {
    "number" : "7.16.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "1a799d8",
    "build_date" : "2021-12-16T01:05:16.99241266Z",
    "build_snapshot" : false,
    "lucene_version" : "8.10.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

To install Redis using Homebrew, run the following command:

brew install redis

To start Redis as a service, run the following command:

brew services start redis

To check if Redis is running, run the following command:

redis-cli ping

You should see an output similar to this:

PONG

You have successfully installed Elasticsearch and Redis for Magento. You will need to configure them later when you install Magento.