There are plenty of options to run the LAMP stack for local development on Mac, and MAMP Pro is one of easiest to configure and use.

However, when it comes to Magento 2 configuration, neither one seems simple and easy. Of course, for Magento 2 development environment, we could use Apache 2 server with MAMP Pro and it should work without any special issues.

After I set up the basic Magento 2 virtual host to work with Apache, I asked myself: What if ….?

Is there any easy option to set up the NGINX config file to work with Magento 2 without affecting the global NGINX configuration?

After some investigation on how MAMP works and what options to override any configuration, I was really happy that I found a way to make it easy and modular.

When a new host is created if we select NGINX as a server for that host, we have the option to override/insert additional NGINX configuration in a custom form prepared for such overrides:

configure mamp1

However, since I will use many Magento 2 hosts, I didn’t want to copy – paste the same configuration options every time I am creating the host. Also, those fields for different parameters could be confusing and mistake in configuration could easily happen.

What I prefer is to have a custom NGINX configuration file in a web root of each site, so I could easily copy-paste complete file for Magento 2 and also do some additional site-specific configuration easily.

Let’s see how to do that:

With MAMP window open, navigate to File / Edit Template / Nginx and that will open a basic NGINX template MAMP is using to create Nginx config file.

configure mamp2

Let’s locate the “MAMP_VirtualHost_AdditionalCustom_MAMP” line inside template file and add the following lines just below this line:


set $FCGI_PASS unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI_phpMAMP_PhpHost_MAMP.sock;
set $FCGI_PARAMS /Applications/MAMP/conf/nginx/fastcgi_params;
       include MAMP_VirtualHost_DocumentRoot_MAMP/.nginx.custom.conf; 


The “set” lines above are adding some variables that we can use in our local conf file and the “include” line is loading the local “.nginx.custom.conf” from our site web root.

After those changes, save the template.

One more step has been left and that is to create a custom Nginx config file for our Magento 2 project and put it inside M2 web root.

The sample file content can be found here:
https://gist.github.com/apiworks/bbb8ec03843e1926089055d634a2c4db

In order to use it, copy that file content in the web root of your project and just change necessary variables and paths in them.

Restart NGINX server and enjoy your Magento 2 run by MAMP Pro and NGINX.

Cheers!

Comments

Leave a Reply

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