Developing with WordPress locally

Up until earlier this year I'd been "going commando" by working directly on the servers using tools like Coda to save and upload straight away. I'd either set up a dev subdomain or work straight on the live site. I'd never really put a thought into developing locally or considered the benefits. The situation arose where I needed to, so recently I've been working with MAMP (Mac, Apache, MySQL, and PHP) installed on my machine. It includes everything you need to run a dynamic website from my local machine.

Get MAMP

The advantages are great: you're basically recreating a server on your computer, which means as long as you're running MAMP, you don't need to be connected to the internet to work. If you're on the train home from work or 30,000 feet in the air you can still carry on working. It also eliminates the constant uploading that comes with working on the server, conserving bandwidth and speeding up the whole process considerably.

Note: If you load any of your files from a CDN, you'll need to download a hard copy.

Downloading WordPress

Download the latest version of WordPress from wordpress.org and extract to your working directory. E.g. /Users/yourname/Sites/wordpress.

Setting up a site

For this post I'll be using MAMP Pro.

  1. Open up MAMP Pro and go to the Hosts tab.
  2. Add a new host by clicking the plus icon at the bottom of the list.
  3. Server name: This will be the address of the site e.g. wordpress.dev
    You can name this whatever you like. Bear in mind if you specify an existing domain you'll be served the local version instead of the "live" version.
  4. Disk location: Change this to the location of your working directory (/Users/yourname/Sites/wordpress).
  5. Hit apply and you'll be prompted to restart the services.

 

 

Now when you visit https://wordpress.dev/ in your browser you should see your site!

Setting up the database

Go back to your MAMP Pro window and go to the Server tab, then MySQL. Click Launch phpMyAdmin, which should open PMA in your browser.

From the PMA homepage, go to the Database tab and create a new database called wordpress with a collation of utf8_unicode_ci.

Go back to your host (https://wordpress.dev/) and enter the database details as follows:

Database Name: wordpress
Username: root
Password: root (you can change this under the MySQL tab in MAMP)
Database Host: localhost
Table Prefix: wp_ (only change this if you want to run multiple WordPress installations from a single database)

Submit. You now you have a working copy of WordPress installed locally on your machine!

© 2020 Dec Norton