Do you love unnecessary hassle when working with WordPress? Relish grinding through theme or plugin development at a snail’s pace? Does your heart skip a joyful beat at the prospect of losing a client by bringing down a live site for totally avoidable reasons? Then this article may not be for you.
If, on the other hand, you’re looking to simplify your working life and take control of your day-to-day WordPress development, keep reading.
We’re going to cover one of the simplest steps you can take to streamline and professionalize your workflow: setting up a local WordPress installation on your Mac.
Before we get into detail though, let’s quickly recap the main reasons why you should do this.
Why You Need a Local WordPress Installation on Your Mac
Here are four solid reasons that will have you wondering why you didn’t do this sooner:
1. You Will Enjoy the Freedom to Work Offline
We’re moving closer and closer to a truly always-on digital world, but the day where you can take an ever-reliable and uber-speedy internet connection for granted is still some time away. Unexpected travel, intermittent network coverage and remote outages are just three reasons your carefully laid plans may be unexpectedly derailed.
Having a local install available means you’re free to work how, when and where you want. That’s invaluable.
2. You Will Be Faster Across the Board
No matter how beefy your server is, reading direct from the local disk is always going to be quicker. All those remote database calls and page loads add up quickly. By working on a local machine, you’re potentially shaving hours of wasted time off your working week.
You also stand to gain from a general knock-on effect on productivity. The type of unexpected, unpredictable delays you inevitably experience working on a remote setup are an absolute killer for productivity and flow.
Get your local setup dialled in on the Mac and you’ll be working faster and more efficiently across all areas of WordPress in a matter of hours.
3. You Can Test Ideas More Quickly
WordPress is an incredible playground for designers, developers, marketers and business owners, but the gap between idea and execution can sometimes be large.
Regardless of your background, the ability to move from idea to prototype in a risk-free, local environment in a matter of minutes will change your creative game.
4. You Won’t Risk Breaking the Live Site
Let’s say it straight: doing serious development work directly on a live site – or making substantial changes without testing their impact locally first – is a trademark cowboy coder move. You need to stop doing it.
Whether you’re looking at specific site changes, or developing plugins or themes that will be deployed on many sites, a local installation gives you a stable, safe working environment to test and refine your work before you deploy anywhere critical.
Hopefully by now you’re convinced of the need for a local install. Now let’s start making your life simpler.
Creating a Local Environment with MAMP
There was a time when getting a WordPress-friendly local development environment working was an arduous job reserved for masochists, command line wizards, or both.
These days, fortunately, it’s a relatively straightforward task, and the basic setup is beginning to rival the speed of WordPress’ own famous 5-Minute Install.
We’ll give pointers for more advanced setups at the end of the article, but by far the simplest way to get started quickly is by using MAMP – an application specifically designed to give you all the ingredients of a local server on your Mac.
WordPress needs two basic things to run:
a web server running PHP, and
MAMP – short for Macintosh, Apache, MySQL and PHP – gives you all of this straight out of the box in one easy to install, downloadable package. Let’s get started.
Download and Install MAMP
Head on over to the MAMP website and download the standard free MAMP package. There’s also a premium version available in MAMP PRO, but the standard version is more than adequate for your initial needs and contains everything necessary for running WordPress locally.
Once the package has downloaded, simply double-click on the MAMP disk image, drag the MAMP folder to your Applications folder and proceed as normally from there.
If you find yourself getting stuck at any stage, consult the excellent installation overview on the MAMP site.
You’re now free to start MAMP by launching MAMP.app, which should be located in /Applications/MAMP/MAMP.app.
Configure MAMP Settings for WordPress
After you’ve launched MAMP, there’s a little bit of prep work to be done prior to installing WordPress. Begin with ports. Click on Preferences, select Ports and then select Set Apache & MySQL ports to 80 & 3306. These are standard port settings for these services that you’ll also see on remote servers, so it’s a good idea to use them here.
Now set your Document Root. This is where your web files reside on your computer and what Apache uses to serve them. By default this will be located in the MAMP Application directory at /Applications/MAMP/htdocs, but you’re free to change it to wherever is most convenient for you. A local Dropbox folder, for example.
At this point, fingers crossed, everything should be working smoothly. Check back on the MAMP launch screen and check if services are running by looking for small green squares at the top right of the screen. If they are not running, hit Start Servers.
Now click Open start page and you should be looking at a version of the screen below.
This is a local web page giving basic information about MAMP and its components. It’s being served directly from your hard drive by Apache.
If you run into difficulties along the way, start with the MAMP documentation. Failing that, remember that Google and Stack Overflow are your friends. Two common gotchas to beware of are Apache or MySQL not starting.
Setting Up Your Database
Now let’s create our first database. MAMP comes with phpMyAdmin (a convenient and powerful tool for managing MySQL databases) installed as standard, so we’ll be using that.
You’ll also find phpMyAdmin installed as standard on many remote hosting environments, so getting used to working with it locally is a great way to brush up your skills in a safe setting.
We need to do two things:
Begin by opening up the Tools menu on the MAMP welcome page and launching phpMyAdmin. Now click on the Databases tab, enter the name of your database in the Create database field and click Create. Use a UTF-8 collation such as utf8_unicode_ci to avoid issues with character encoding down the line.
Now navigate to the Users tab, click Add user, enter a name and secure password and set the host to local. Then return to the Users tab, select Edit privileges on the user you just created, click Check all and save. We’re assuming here that this database will only be used locally and by yourself.
Make a note of the database name along with the user name and password. You’ll be entering them again shortly.
If you run into difficulties at this stage, head on over to the WordPress guide to using phpMyAdmin and troubleshoot from there.
The stage is now set and you’re free to move on to more familiar ground by installing WordPress itself. The process here is essentially the same as installing on a live server; the server just happens to be located on your machine.
Begin by downloading the latest version of WordPress and extracting it to a named folder in the Document Root you defined earlier. Let’s assume in this instance you call the folder my-wordpress.
Make sure MAMP is running Apache and MySQL and navigate via browser to the WordPress install script in that folder. Use the address format localhost:port/folder_renamed/wp-login.php. In our example that would be localhost:80/my-wordpress/wp-login.php.
Navigating to there should kick you into the familiar WordPress 5-Minute Install sequence. Complete this using the database details you created previously and you are now free to develop locally at your leisure.
Taking Your Local WordPress Install to the Next Level
Congratulations! You are now covered for basic local development in WordPress. At some stage though, you’re going to be looking to spread your wings a little in terms of the complexity and sophistication of your setup. Here are three more advanced topics to explore when you’re ready to take your local WordPress environment to the next level:
1. Desktop Server
Desktop Server is a tool for automating and managing many of the steps we’ve just taken across multiple local installs. It can also be used to sync these local sites with live environments. Free and premium versions are available.
2. Varying Vagrant Vagrants
Not for the faint-hearted, Varying Vagrant Vagrants is a sophisticated approach that leverages the power of virtual machines in Vagrant to create programatically reproducible WordPress development environments. There’s a great intro to the concept over at WebDevStudios.
3. Exploring Development Workflow
We’ve concentrated on the local environment here, but more sophisticated setups will call for a full local -> staging -> production workflow. This is a vast topic, but you can start dipping a toe in the water with WordPress Tavern’s overview.
Whether you’re a developer, designer or site owner, getting WordPress set up locally is going to save you a huge amount of time and a lot of sleepless nights. And, as we’ve hopefully shown, it’s not that difficult to do. Here are the basic steps again just to recap:
Download and install MAMP,
Set up your database and database user with phpMyAdmin, and
Install WordPress locally and get to work!
Once you have the basics set up, a world of further optimization options will open up for you. Let us know where you take it in the comments below and feel free to share this tutorial with others who you think might find it useful! Feel free to let us know if you also want more information about using Avada with WordPress.