Setting Up a WordPress Development Environment on Mac OS

I've had my current laptop for a little over 3 years, which means it's been that long since I last setup my development environment.

Setting up a dev environment is one of those things that you don't have to do often (hopefully) so it's easy to forget all the little quirks and gotchas that you have to go through to get things running smoothly.

Since I'm mentoring new coders in the Ascend Project, it seems like a good time to refresh my memory on these steps and commit them to ones and zeros for referencing in the future.

I'm basing most of this post on a great write up by Chris Mallinson of Vancouver B.C. who has a setup very similar to mine. I'll be adding more detail in places to make things more beginner-friendly.


In order to run WordPress locally, you need the following:

  • Xcode
  • Apache
  • PHP
  • MySQL

1. Get Xcode

Xcode is necessary to use many of the developer tools you'll need so if you don't already have it, download it here or through the Mac App Store. Have a good book or some other amusement handy for the wait.

2. Configure Apache and PHP

Apache is installed by default, but you have to tell it to use the php module to handle files ending in .php.

This configuration file lives at /etc/apache2/httpd.conf. Open this file (you'll need root privileges to edit) and find the line (117 on my machine) that says:

#LoadModule php5_module libexec/apache2/

Uncomment it by removing the ‘#' from the beginning of the line.

Next we want to tell Apache to allow us to load multiple websites. Find the line (477) that says:

#Include /private/etc/apache2/extra/httpd-vhosts.conf

Uncomment this line the same way.

Save the file.

Configure Virtual Document Root

This is what allows you so setup a single folder to hold all of your projects and then serve one site per folder inside that projects folder. So for instance, I have my web projects in /Users/Kronda/Sites. Then, insides the Sites folder, I have project/webroot. The actual site files go inside the webroot folder. When I go to I get that project.

1. Configure Your Host File

Choose a domain that you will use to refer to your local domain. I'm going to stick with Chris's example and use Open your hosts file, which tells your computer how to resolve IP address. It's located at /etc/hosts and requires root privileges to access.

Add the following lines to the bottom of the file: 

Save the file.

Install dnsmasq

brew install dnsmasq
cd $(brew --prefix)
mkdir etc
echo 'address=/.dev/' > etc/dnsmasq.conf
sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
sudo mkdir /etc/resolver
sudo bash -c 'echo "nameserver" > /etc/resolver/dev'

Next open up /etc/apache2/extra/httpd-vhosts.conf (requires root access)

Add the following to the end of the file, replacing ‘username' with your own username from your Home folder:

    VirtualDocumentRoot "/Users/username/Sites"
    UseCanonicalName Off

  VirtualDocumentRoot "/Users/username/Sites/%1/webroot"
  ServerAlias *.dev
  UseCanonicalName Off

Save the file and then restart Apache to load the new configuration by running:

sudo apachectl restart

Install MySQL

  1. Go to the MySQL Download page
  2. Since Chris reported problems with running the latest version of MySQL on OX 10.9 and 10.10, scroll down to the Mac OS X 10.7 (x86 64-bit), DMG Archive and download that one. Note: make sure you get the 64 bit version and the DMG, NOT the TAR Archive.
  3. The next page will ask you to create an Oracle account. Ignore that and and scroll down to the tiny text that says ‘No thanks, just start my download' and click.
  4. Find the downloaded file which should be named something like mysql-5.6.20-osx10.7-x86_64.dmg. If you double click to open you may get a message saying that your security preferences allow installation of only apps from the Mac App Store and identified developers. If that happens, open it by right clicking and choosing Open with > It will still warn you, but you'll get an option to open anyway so click ‘Open.'
  5. Then click through all the agreements and type your admin password when prompted.
  6. Once the main install is complete, go back to the DMG disk and follow the same steps with the MySQLStartupItem.pkg
  7. Lastly, go back to the DMG disk one more time and open the MySQL.prefPane
  8. Install for all users
  9. Start MySQL Server and make sure Automatically Start MySQL Server on Startup is checked.

Next you'll want to make sure you can access mysql via the command line. To do this, you'll need to add the path to the mysql binary to your PATH variable in your .bash_profile file, located in your home directory. (~/.bash_profile)

By default mysql will be installed at /usr/local/mysql. If you open Terminal and run

cd /usr/local
ls -l

you'll see mysql listed, which will be a symlink to the specific version folder which will have a longer name like mysql-5.6.20-osx10.7-x86_64. It should like something like:

mysql -> mysql-5.6.20-osx10.7-x86_64

Run the following to add mysql to your path:

export PATH="/usr/local/mysql/bin:$PATH" >> ~/.bash_profile

Now open a new terminal window and run

which mysql

It should return the location of the mysql binary.

By default MySQL does not set passwords for database users, but it's a good idea to secure your MySQL installation. You can find the instructions here. Scroll down to Assigning root Account Passwords

Congratulations, you're now ready to download and install WordPress!

Posted in , Tags:

Kronda Adair

Kronda is the CEO of Karvel Digital, a digital marketing agency that helps established businesses double their revenue in 12 months using online marketing. She loves empowering small business owners to not be intimidated by all this tech stuff. She's often covered in cats.

Want more tips like this?

Get actionable insider advice every Sunday: