The Mijingo Blog

Latest news, updates, free tutorials, and more from Mijingo.

SSL/Non-SSL Site Locally with MAMP

by Ryan Irelan

In the last blog post we walked through how to set up MAMP Pro for SSL websites. This assumed that your website would be SSL all the time, for every connection. While more and more sites are becoming all SSL, many still only invoke SSL connections for critical situations, like signing in or authenticating, important form submissions, and financial transactions, like purchases.

In these SSL and non-SSL situations, a site visitor is being ushered between secure (SSL, https) and insecure (http) connections, depending on what they’re doing on the site. On Apache, this is typically set up as two different host records, one for port 80 (http) and one for port 443 (https).

When setting this up locally–as a way to emulate how our production server would work–we also need to set up two different host records on Apache.

This tutorial requires that you have a paid (or trial) copy of MAMP Pro.

Set up Non-Secure Host Record

First, let’s set up a normal MAMP host record.

(If you’re new to localhosting, I recommend our free course on localhosting, which includes how to use MAMP.)

Create the MAMP site to point at the local (public) directory of the site files you want to use. Restart the MAMP servers and then go to the site URL to confirm that it is working.

Set up Secure Host Record

This part is already covered in the previous tutorial on setting up SSL on MAMP. In summary: we’ll need to create the new host record for SSL–pointing to the same local directory as in the first step–and make sure we check “SSL” as part of the setup.

Redirecting from Non-SSL to SSL

Unless your software, CMS, or web application is set up to handle the redirect from non-SSL to SSL based on URL, you will want to do it with a redirect, using mod_rewrite rules.

Every situation will be slightly different but here’s an example of how I redirectred non-SSL connections to SSL:

RewriteCond %{HTTPS} off
RewriteCond $1 ^(account|cart/checkout|admin) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This starts with a mod_rewrite conditional to check if the request has HTTPS off (meaning it’s a non-secure request, over port 80), then it checks if the request has one of the URIs listed (delimited by pipes).

I can add as many URIs there to check as I wish. In this example, I’m checking for account, cart/checkout, and admin. These are all common examples of places you’d want to have SSL connections.

If the conditions evaluate to true, then the request is redirected to an https of the same URL. We’re using some variables to grab the current HTTP host and request URI.

Now when someone access, Apache will redirect to https://mijingo./dev/account automatically, never allowing /account to accessed over port 80.

Develop SSL Sites Locally with MAMP

by Ryan Irelan

Local development of SSL sites with MAMP (see our course covering MAMP and other localhosting tools) takes just a few steps to set up. If you’re using MAMP (the free version) you will have to upgrade to MAMP Pro to set up SSL locally.

Here are the steps you need to take to set up an SSL site with MAMP Pro.

Create the Host

Just like we would with a non-SSL site, we have to create a new host first. In MAMP Pro we do this by clicking the + button at the bottom left of the main window. That will create a new entry in the Hosts listing. Name it whatever you want (I’m using for my localhosting of this site).

If it’s not already, select the new host so you expose the hosting settings on the right side of the window.

I’m working under the assumption that you use the standard Apache ports for MAMP Pro (80 and 443). If you’re not, your site will not be available at the standard SSL port (443). I suggest running the same ports locally as you do in production, just so everything is the same.

Enable SSL

Next up is to enable SSL for our newly created host. With the host selected on the left, click the “SSL” tab on the right side of the MAMP main window.

Check the SSL box to enable SSL for this host. With SSL enabled we need to create certificates so we have an encrypted connection.

Fortunately, we don’t have to buy an SSL certificate for our local development (although, I suppose, we could). We can use what’s called a “self-signed certificate” instead.

A self-signed certificate means that we sign the certificate ourselves to verify its authenticity instead of going through a certificate issuing authority that verifies the certificate is indeed from us. Since we’re just using this locally–and not to serve any pages to the public–using a self-signed certificate if perfectly acceptable.

Create a Certificate file and key

There are two parts to creating an SSL certificate: a certificate file and the certificate key file. MAMP Pro makes it really straight-forward to create both.

Click the button “Create self-signed certificate…” and then fill out the form with your information. The form you input will only be used to create the certificate files on your computer and not sent anywhere.

Creating a Self-signed Certificate in MAMP Pro

After submitting the form, choose the location to save them. I typically choose the project directory or my computer user directory. MAMP Pro will create the certificate files and then add them to your config automatically.

MAMP Pro with SSL Certificates

Save your host file using the Save button.

Test the New Host

Confirm that MAMP Pro restarted the servers properly and then test the URL out in your browser. In my case I’d go to and it should load the site properly over SSL and port 443.

Now that you have that done, learn more about localhosting in our free course Reliable Localhosting.

Free Course: Reliable Localhosting

by Ryan Irelan

We released a new, completely free course on how to do localhosting on Windows, OS X, and Linux.

At the conclusion of this video course you will be familiar with five different ways to localhost on OS X and Windows. Ryan walks you through each application–from installation to configuration–so you can find one that works for you and get up and running with a reliable localhosting environment.

The course is 5 parts and run about 45 minutes. All free! Start learning now.

What are our customers saying?

"Just purchased your Flexible Twig course. Love it!"
Tyler Morrison
"Been enjoying @mijingo 's Learning Craft video tutorials. Feeling like I've got a good basic understanding of #craftcms Very impressive"
Laura Montgomery
"I bought your Craft Starter Pack a year and a half ago. Worth every dollar. In fact, I would've paid twice as much for it, because you saved me so much time."
Timothy Ingram
"Ben's knowledge of Craft combined with his relaxed and informal teaching style makes for a great learning experience."
Steve Abraham
"Ben puts a lot of thought into his teaching approach and has the ability to explain complex concepts in a way that just make sense"
Gareth Redfern
"Ben is great at taking a complex subject and breaking it down in a way that you can wrap your mind around. I thought that plugin development was something I would never understand, and happily Ben proved me wrong!"
Jonathan Melville
"I really appreciate all the videos and writing you have done. Your work has given me a jump start on my front end development business."
Shan Ricciardi

Perfect for Small Teams & Companies

Mijingo's courses are perfect as the training curriculum for both small teams and entire companies.

Our courses are offered in Team Packs (up to 5 people) and Company Packs (up to 25 people), so you can make one simple, fast purchase to train your entire staff.

Prices are listed with each course. Need more than 25 or something custom?

Send Your Requirements
Team Pack2-5 People
Company Pack6-25 People
Custom Pack25+ People