MAMP PRO for Local WordPress Development

I’ve used a few different options for local development on my laptop over the years. I’m at a transition point in my career and I thought I would take a minute to post on my workflow. I hope it helps others and serves as a reference point for me in the future.

For a while I used MAMP. Everything was subfolders of localhost and it worked. It wasn’t fancy but it gave me a working development environment to build and break things.

I remember when I updated my version of MAMP I screwed up and lost a lot of my local databases. Nothing lost was critical, but a lot of the learning projects I had built over the years. Because of this I was pretty frustrated with MAMP and I decided instead I should change my approach. I knew about VVV from listening to WordPress podcasts and it seemed like the right way to go.

Variable Success

VVV is great, though I’m not sure if I ever got the most out of it with my older laptop. I’m still rocking a MacBook Pro late 2009. It gets the job done and I’m looking for the next option but it never quite liked having Vagrant running. I remember the first time I used vagrant up it took FOREVER to download and run everything. When it finally started running I did enjoy using VVV as well as Variable VVV for site creation. The custom local domains and everything did work, for a while.

Over time I ran into more and more problems with VVV. It was either my Vagrant, or Oracle’s Virtual Server, or something else altogether. It’s quite possible I was doing something wrong, but I never did figure it out. One day several sites stopped working and no amount of restarting could alleviate the problem.

I tried to use Desktop Server, but it saw that I had another virtual machine installed on my computer. Even though I had deleted everything Desktop Server would never let me install.

By this point I need something that would work. I decided to throw some money at the problem and ponied up for MAMP PRO.

The main issue I have with MAMP is the lack of good documentation. There some info on their site and now that I have things running I’m having a good time. I hope this post will help others who look for ways to get the most out of the MAMP PRO software.

MAMP PRO Workflow

I started a new remote position about a month ago and many of the projects are editing existing websites. This meant I first needed to get a working local copy of the website. And several of them are HTTPS.

MAMP PRO has a easy way to set a server to use https. When making a new site or changing an existing one you can go to the SSL tab and check the box to turn on SSL. If you have certificate files you could point to them, or you can “Create self-signed certificate…” which lets you setup your own local certificate. Enter any info, it doesn’t matter. When you open the site in browser it will warn you saying that the certificate isn’t secure. You agree that you understand it will continue to the site and work as normal.

mamp-pro-ssl

Apache or Nginx

A nice feature of MAMP PRO is the ability to individually select Apache or Nginx for each site. I started with doing everything as Apache as that’s what I’m used to and it made the transition easy. But I ran into a situation where switching to Nginx was a game changer.

The development sites all had repositories for the theme and I used WP Migrate DB PRO to pull down the database. But instead of downloading all the images they use an Nginx directive to rewrite the file locations to point everything to the live server.

Local Development, Remote Images

In the Nginx tab of MAMP PRO you can add extra parameters for the directive. Here I add

location ~ ^/wp-content/uploads/(.*) {
  if (!-f $request_filename) {
    rewrite ^/wp-content/uploads/(.*)$ http://www.websitename.com/wp-content/uploads/$1 redirect;
  }
}

After the location tag is a regex. It’s looking at any file request that has a beginning, then references /wp-content/uploads/. Then collects whatever comes afterward. If it’s a filename being requested we rewrite that same regex and change it to the live site and use that saved file extension from the search.

Now you don’t have to deal with downloading years worth of images from an existing website.

mamp-pro-nginx

I found that this works, but with Nginx I have an issue with any of my links. They all lead to 404’s. While still in the Nginx tab add the following to the try_files parameter

$uri $uri/ /index.php?q=$uri$args;

This line uses Nginx’s rewrite rules to work with WordPress routing and run everything through index.php. It also keeps the arguments that are part of the url. The $uri here is commonly used to represent everything after the domain name in the URL.

MAMP Bonus

Another bonus to using MAMP is the ability to install “Extras” which include WordPress. With a couple clicks you can install, and setup a database for your WordPress development. Combo this with some command line skills to pull down your favorite WordPress starter theme and you’re all set to build new and exciting WordPress sites.

There is a file that is created in the root directory called extras to show an icon in your MAMP Hosts for each extra you have installed. It’s a little annoying and I normally delete it or just include in my gitignore.

Is anyone else out there using MAMP Pro for your local WordPress development?


in

Comments

Leave a Reply

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