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.
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.
git clone email@example.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.
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 :
If the output is
/usr/bin/php it means the default OSX PHP version is loaded and we need to change it.
sudo nano ~/.bash_profile
Add this line and save:
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:
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!
6. Improve Speed
A fresh install of Magento 2 slow on localhost? Check this post where I share some steps you can take to make your Magento 2 faster on your localhost.