Developing in a local environment can be a real asset when you’re developing for the web. Not only will developing locally be faster than waiting for file uploads via FTP, testing new features on your local machine will always be safer than testing them live.
Setting up a local WordPress installation isn’t difficult, but it can be a bit tricky if you haven’t done it before. This tutorial is designed to walk you through the process from start to finish. I’ve also included an optional step for those interested in running WordPress Multisite locally, though those interested in a standard WordPress installation can easily skip over them.
So you know, these are the steps we’re going to be taking to install WordPress locally on a Mac:
- Download and install MAMP
- Edit your hosts file (optional)
- Load WordPress files into your new /htdocs folder
- Edit your wp-config.php file
- Load up your editor of choice and enjoy local development!
Enough prep, let’s get started!
Step 1: Download and install MAMP
In order to run WordPress, we need to have MySQL and PHP running on our Mac. A simple way to do this is an app called MAMP, which stands for “Mac, Apache, MySQL, PHP” and sets up a local environment on your Mac.
MAMP can be download here, and installing it is just as straightforward as installing any other application.
Once it’s running it will open up the MAMP start page, which will double as confirmation that it was installed correctly as well as quick links to phpMyAdmin and other database information. Here you will see that the database username and password is, by default root and root. You can change this if you want, but as far as I know there is no point to doing so.
One suggestion I do have is to go into the MAMP Preferences panel (seen to the right) and select “Set to default Apache and MySQL ports” to set the Apache port to 80 and the MySQL port to 3306. It should match the settings of the screenshot on the right.
With MAMP fully configured, visit phpMyAdmin from your MAMP start page and create a new database for your WordPress installation. Keep the database name in mind.
Step 1.5: Edit your hosts file (optional)
This is an optional step, though it is necessary for running WordPress Multisite.
If you don’t understand what is is, see our introduction to Multisite.
WordPress Multisite cannot operate with a port number in the URL (
http://localhost:80/ for instance) so we want to map a new URL to our localhost address. To do this, first open up Terminal (don’t worry, it’s not too scary!).
In order to map a new URL to localhost, first enter:
sudo nano /private/etc/hosts
This will bring you to your hosts file within Terminal. You may need to enter your admin password to access it.
Once you have access to the hosts file, navigate down to the bottom of the list and add the following line, with a tab separating them:
Note that the URL you enter (in my case, wp.dev) can be anything you want. I would recommend choosing something short and memorable.
To save the hosts file, press
Control + O and hit enter. This will save your hosts file, and you can close Terminal. You will know if it works if you visit the URL you chose and it brings you to your MAMP files.
Step 2: Load WordPress files into your new
We’re now ready to install WordPress, which I’m sure you are familiar with. Download WordPress and move the files into your
/htdocs file, which will be located within the MAMP directory in your Applications folder.
At this point you have the option to either create a subfolder for your WordPress installation or to add it directly into the root. In this case we’re doing it at the root, though you are free to do what you want.
At this point it wouldn’t be a bad idea to also rename your
wp-config-sample.php file to
wp-config.php. We’re going to be editing that in the next step.
Step 3: Edit your
Now we will add the Assuming you didn’t change the root username and password, use root for each along with the name of the database you created back in Step 1. I called my database wpdev, so my file looks like this:
Save this file and visit the home directory to complete the installation process.
Step 4: Load up your editor of choice and enjoy local development!
If everything above went smoothly, you should now be looking at a solid local copy of WordPress, primed and ready for testing and development. Crack open Textmate, or Coda, or your application of choice, and have some fun.
Are you using WordPress locally? What do you use it for, and how has it helped you in your work?