DEV Community

Cover image for The Ultimate Guide to Local WordPress Development on a Mac

The Ultimate Guide to Local WordPress Development on a Mac

David Vincent Gagne on February 21, 2017

It's a bold title, I know. But I have been working to achieve this for about five years now and am finally very satisfied with my configuration. If...
Collapse
 
traaidmark profile image
Adrian Kirsten

I am by no means a pro-level wordpress dev, but I do a fair amount of work on the platform.

If you'll allow me, some thoughts on your article here:

I generally work with $jsframework which means I rarely need a proper server setup on my local machine, but I did follow Chris's guide too for the times I do need one, and it works great, right up to the point where I want to access $site from my phone over the wifi network. For some reason that xip.io thing just refuses to work. eh.

At first when I read that you only add your theme to a repo I found it quite strange, but the more I thought about it, it makes a lot of sense. My experience with Wordpress, especially moving it around is not a great one, and now I think of it, most of that negativity comes with moving the entire wordpress platform from local to staging to production, and not just the theme.

And it makes sense. Wordpress itself doesn't change much.

If I can add something to your guide to make it the SUPER ULTIMATE GUIDE TO LOCAL WORDPRESS DEVELOPMENT (with uppercase and all!):

I realise you don't enjoy working in the terminal much, but... and here me out on this one, it will literally change your life: Add WP CLI to your toolbox.

Once you've gotten that working you're ready to start really cooking. Download a copy of WordPress, unzip it, and drop it into ~/Sites/wordpress/ first. You're going to run into some permission issues probably, but you can handle them with:

Or:

  • $ cd ~/Sites/wordpress/ to get you in your working folder
  • $ wp core download - Downloads the latest wp to that folder
  • $ wp core config --dbname="wp-experiment" --dbuser="whatevs" --dbpass="shhh" --dbhost="127.0.0.1" --skip-check - creates your wp-config.php file for you.
  • $ wp db create - creates the db for you using the deets you entered into your wp-config.php file.
  • $ wp core install --url=example.com --title=Example --admin_user=supervisor --admin_password=strongpassword --admin_email=info@example.com - does the wp install in seconds.

You now have a running wordpress site! The cooler thing about the wp cli is that your average maintenance becomes a lot quicker.

  • $ wp core update - updates your wordpress installation
  • $ wp plugin update - updates all your plugins
  • $ wp plugin install bbpress --activate - install & activate a plugin

There is obvs a whole lot more it can do, especially around migrating content/db between servers etc.

You could for example create a very simple bash script that runs some of these commands for you to move all your uploads to another server, migrate the content/db, change urls etc for you.

Collapse
 
andrewdurber profile image
Andrew Durber

Great article. Not a WP dev, or even a PHP dev for that matter. But I've recently been doing some theme development and decided to go with Varying Vagrant Vagrants TL;DR:

1) Install VirtualBox (if not already installed)
2) Install Vagrant (if not already installed)
3) Clone the VVV repo or download the latest stable release
4) In terminal (or cmd, it works cross-platform), cd into the directory where you cloned the VVV repo, type vagrant up.

It does some provisioning but once it's up it's a delight to work with. The beauty of it being in Vagrant is that I have the same environment across all of my machines (OS X and Windows 10) with:

  • nginx
  • WP-CLI
  • phpMyAdmin
  • Wordpress Develop
  • Wordpress Stable

To name but a few.
VVV: Intstalled Packages

It's a little overkill but, it's a great environment with everything that I need, and then some.

Collapse
 
nearlythere profile image
Heather • Edited

I think installing natively on Mac seems less troublesome because it's something we know. Docker offers lots of potential, but it's like: do I need to learn yet-another-thing? I think so many Docker-based solutions are coming up because once people figure out, they want to share it like evangelicals. That makes decision making a little tricky.

Anyway!

Here’s a video tutorial on how to set up a Docker-based PHP local development environment for macOS using this handy tool called DDEV. You have all the flexibility you'd have with Docker, but it "just works" out of the box, taking care of lots of things for you.
drud.com/ddev-local/how-to-set-up-...

Bonus: The same tool, DDEV, works on Linux and Windows (with an installer) and you can use it with any PHP application. There are some helper tools for popular CMSs too.

Disclaimer: I work with these people and they are awesome <3

Collapse
 
erebos-manannan profile image
Erebos Manannán

It's 2017, please stop recommending people run any development environments on their host OS. Vagrant exists, you should use it.

After setting up your environment in Vagrant learn to take snapshots of the images, or better yet use SaltStack, Ansible, Bash, or some other tool for installing all the requirements and configuring the VM automatically, and you're a long way into having a reasonable development environment and deployment strategy.

Collapse
 
splitinfinities profile image
Will ᕙ🇺🇸ᕗ

Try Local by Flywheel! It uses docker and it's zippy quick. I work at Flywheel, but I also used to work at an agency and still do freelance work, and Local is such a dream to work with. You can download it here: local.getflywheel.com

Collapse
 
davidgagne profile image
David Vincent Gagne

Thanks, Adrian. I'll take you up on exploring WP CLI for sure.

You're right about storing all of WP in a git repo. Since I wrote this I've moved to only keeping my themes and not all of wp-content in repositories. On my machine I just have a standard database with the suite of test data that I use for developing all my themes.

Collapse
 
gromnan profile image
Jérôme TAMARELLE

Pro top: use docker for local development. And you will never ever mess your http.conf

docs.docker.com/docker-for-mac/ins...
docs.docker.com/compose/wordpress/

Collapse
 
martyonthefly profile image
Sylvain Marty

Very good article ! :)

I'll give it a try but I'll gonna call the repository Kenobi and I hope it will have the Hight Ground again ! :P