install magento 2

This is a short step by step tutorial about how to install Magento 2 locally on MAMP. We will see how to install MAMP and how to configure the proper PHP and MySQL versions.
We’ll then connect to Github and get Magento 2 sources and install it via Composer.

You can see what’s new in Magento 2 in my previous article.

1. Install MAMP

You can find the latest version of MAMP (My Apache-MySQL-PHP) to download from their official website.

Setup proper PHP and MySQL versions

As of writing this article the latest stable release of Magento is 2.1.8. This version requires MySql 5.6 and PHP 5.6.5-5.6.x or PHP 7. You find details about requirements here.

Be sure you setup MAMP to use these versions of MySQL and PHP. The latest version of MAMP already comes with MySQL 5.6 but if you have version 3 or below here is a quick guide on how to upgrade. For PHP I recommend version 7.

2. Github

Next thing to do is to get Magento 2 repository on our local environment. Make sure you have GIT installed. Go to Github and sign up if you don’t have an account. If this is your first time on Github you need to add your SSH key.

A quick command to copy your SSH key to clipboard:

pbcopy < ~/.ssh/id_rsa.pub

Add Github to your known hosts list:

ssh-keyscan -t rsa github.com > ~/.ssh/known_hosts

Here is a detailed explanation about connecting to Github with SSH

Now that you can connect with SSH to Github you can pull the Magento repository to your localhost. Be sure you are in your localhost folder and clone the repository.

cd /Applications/MAMP/htdocs/
git clone git@github.com:magento/magento2.git

3. Install Magento via Composer

We now have Magento repository on our local machine and we need to install it via Composer.

Install Composer

If you already have Composer skip this step. But if you don’t, you can install it by running:

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

To make it globally accessible move it to your local bin:

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

Edit your bash profile with:

sudo nano ~/.bash_profile

add this line and save it:

alias composer="php /usr/local/bin/composer.phar"

Additional PHP modules

We need to be sure that PHP modules ext-mcrypt and ext-intl are loaded. PHP 7 that comes with MAMP already has them, we just need to be sure the OS uses the MAMP version.

Check the location of PHP :

which php

If the output is /usr/bin/php it means the default OSX PHP version is loaded and we need to change it.

Edit .bash_profile:

sudo nano ~/.bash_profile

Add this line and save:

export PATH=/Applications/MAMP/bin/php/php7.0.0/bin:$PATH

Then run:

source ~/.bash_profile

Running which php again should show the proper MAMP path.

Install Magento 2

We can now finally install Magento. Navigate to your htdocs folder and run the following command to install Magento 2:

composer install

4. Setup the database

Next step is to create a database for our Magento. You can do that using MAMP’s phpMyAdmin. Save your user and password you’ll need them at the next step.

5. Finish Installation

Finally you need to setup Magento via Web Setup Wizard by opening the URL of your localhost installation into the browser. Follow the instructions on the screen.
You’ll probably need to set the right permission to the files. You find the info here.

To install Magento 2 locally is not that complicated, now you can develop on your local machine. Happy coding!


Leave a Reply

Your email address will not be published. Required fields are marked *