Using WordPress in a local server environment is a must if you regularly test or develop themes and plugins.
Not only will your local sites run faster, but testing new features on your local machine will be safer than testing them on a live site.
Setting up WordPress locally isn’t difficult and will save you a lot of time if you’re constantly installing and uninstalling WordPress online.
In this tutorial I’ll walk you through how to set up MAMP on OS X, including installing MAMP, basic MAMP configuration, creating a MySQL database, and installing WordPress. I’ve included optional steps for setting up Multisite.
What is MAMP?
MAMP, which stands for Macintosh, Apache, MySQL and PHP, is an application that allows you to install a local server environments on your Mac OS X computer.
WordPress isn’t a stand-alone application and needs server software to run. MAMP provides the necessary server setup so you can run WordPress on your computer rather than on the internet.
The MAMP file is 245MB. Once downloaded, install MAMP like you would any other software for OS X.
Once installed, launch MAMP. The software may ask you about using MAMP PRO. Just ignore this and continue using the free version for now.
You will need to fix your MAMP settings before you can install WordPress.
1. Click on “Preferences”. Another window will pop up. Click on “Ports” and then click “Set Apache & MySQL ports to 80 & 3306.” These are the recommended ports, rather than using the defaults.
Next, click on the “Apache” tab and choose the location where you will install WordPress. The default location is Macintosh HD/Applications/MAMP/htdocs. This is similar to the public_html folder on your web hosting server.
I like to keep things organized, so I set my document root to Macintosh HD/Users/Rae/Documents/Test Site.
Creating a MySQL Database for WordPress
Before you install WordPress, you will need a database. MAMP ships with phpMyAdmin so we’ll use that to create a new database.
1. Open MAMP and click on “Start Servers.” You may be prompted to enter your computer’s username and password.
2. In your browser (Chrome or Safari or whatever you use), enter http://localhost/phpmyadmin/. The phpMyAdmin interface will appear. Click on “Databases.”
3. In the text area under “Create database” enter a name for your database and click “Create.” I’ve called my database “WP”. You don’t need to worry about any other options so you can close phpMyAdmin.
Download and Set Up WordPress
Download the latest version of WordPress. Extract the files to the document root folder you selected earlier. In my case, I’ll unpack all my WordPress files to Macintosh HD/Users/Rae/Documents/Test Site.
Open wp-config-sample.php and rename it wp-config.php. Open the file and scroll down until you see the following lines:
These lines of code define the login details for your database. Replace “database_name_here” with the name of your database, which in my case is “WP.”
Replace “username_here” and “password_here” with “root,” which is the default username and password.
Save the file.
In your browser, go to http://localhost. You should see the welcome screen for the famous five minute WordPress installation process.
Enter your details and click “Install WordPress.”
Your WordPress installation is now complete!
Setting up WordPress Multisite
Having Multisite setup on a local machine provides not only a way to test themes and plugins in a Multisite environment, but also a quick and easy way to have multiple sites running at once.
Open your wp-config.php file again and add/edit the following lines to activate Multisite’s installation mode:
Open MAMP and ensure your servers are running.
Login to your localhost site and under “Tools” you will now have a new option, “Network Setup.”
Enter a name for your network and your email address, then click “Install.”
WordPress will prompt you to edit your wp-config.php and .htaccess files.
Following the onscreen instructions, open wp-config.php and add the following lines underneath your previous edit:
Next, open .htaccess. If you can’t find it, make sure hidden files are displaying on your computer.
Your .htaccess file should look like this:
Multisite should now be enabled and working on your WordPress site!
MAMP provides an easy way to run a local server environment on your OS X machine, allowing you to test and develop locally, rather than installing WordPress online. It will also save you time since you won’t have to install and uninstall WordPress each time you test themes and plugins.
MAMP is free, but there’s also a premium version that makes it even easier to set up databases and other options so you can use WordPress on your local machine.
Tomorrow, I’ll walk through how to set up DesktopServer on OS X for WordPress localhost development. And not to forget Windows, I’ll look at WAMP this week as well.
Do you use MAMP? Tell us in the comments below.