Rachel H Kay Blog

Setting Up A Local Install of Your WordPress Site With MAMP

Setting up a local environment on your Mac can be a difficult task for those who have no idea what they are doing. While searching in Google can bring up a lot of posts that show you step by step how to set up your Mac for testing websites locally, it may be something you just don't want to bother with. The simplest solution? Using MAMP to setup the local environment instead. Oh, and one other thing, MAMP is free, so that should settle any worries right off the bat.

To get started go to www.mamp.info to download the latest version of MAMP. Once you’ve download MAMP to your computer and installed it you will then need to do a little bit of configuration before you can begin using it. When you open MAMP you will need to click on Preferences.

In the first tab, “Start/Stop” you can select whether you want MAMP to automatically start the servers, Apache and MySQL, when you open MAMP. You can also select if you want the WebStart page to open automatically as well. Choose the options that work best for you.

Then move over to the “Ports” tab to make sure the default ports are set correctly. The default Apache port is 8888, and the default MySQL port is 8889.

The “PHP” tab is where you will select which version of PHP you want to use. The one thing to remember here is that MAMP will only allow you to choose from two PHP versions, which will be the two latest versions you have in the PHP directory in your MAMP installation.

Setting Up Your Site In MAMP

Now you need to set up a local installation of your website. In order to do this you will need to do a complete backup of your website. This will include your WordPress files and your database. Hopefully you are already taking backups in case anything ever happens to your website, so I won’t go into detail on how to take a backup.

Step 1: Copying Your Website Files For MAMP

Now that you have a backup of your site downloaded, put it in a safe place and unzip the folder. Once the folder is unzipped, change the name from the name of the backup to something simple like the name of your website, mywebsite (the name of your website).

Before you begin copying the files in this folder into MAMP, if you downloaded a complete backup of your site, you need to remove your database, which will be imported into phpMyAdmin later on. Open up the folder you just renamed with the name of your website and look for a folder called "mwp_db". This folder contains your database. Move that folder out of the main folder you renamed with your website name, and keep it in a safe place.

There is a ".sql" file in that folder, which is your database file. Make note of the name of that file, we will need it later on when we create your database.

If you downloaded your Wordpress files and your database separately, then unzip your database backup and make note of the name of the ".sql" file in that folder.

Once the database folder is moved out of the backup folder you re-named with the name of your website, you need to copy it to the document root of MAMP. The default document root for MAMP is /Applications/MAMP/htdocs. You can see what your document root for your MAMP installation is by going to the "Web Server" tab in the preferences pane. Unless you chose your own document root it should be the same.

In order to make sure you copied over your site files in the directory root of MAMP successfully you need to open up your site in a browser.

Step 2: Starting MAMP

Go ahead and open MAMP if it isn’t open already. If you didn’t set up the MAMP servers in the "Preferences" pane to start automatically when you open MAMP, then go ahead and click “Start Servers” in the MAMP window. Both the Apache Server and MySQL Server boxes will light up green, telling you that MAMP is up and running, and ready to go.

Your MAMP WebStart page should open in your default browser, if you selected for it to do so in the preferences pane. Otherwise click “Open WebStart page” in the MAMP window. Once you’ve done so your WebStart page should look something like this:

In order to view your site in a browser you need to click on "My Website" in the navigation bar of the WebStart page.

This will take you to a list of all the folders you have in your MAMP document root folder. If this is the first site you've put in your MAMP folder it will be the only one you see. Click on the name of your website, then you should see a screen that looks like this:

No worries, while your site files were successfully installed into the directory root of MAMP, you still need to setup your database.

Step 3: Creating And Importing Your Database

Next you will need to create a database for your website. MAMP comes with phpMyAdmin already installed, which is where you are going to put your sites database. You can open phpMyAdmin very easily from the WebStart page, located under MySQL.

Once phpMyAdmin is open you will need to add a new database, which will be a blank database for now, but don’t worry, we will get your database files in there shortly. Click on the “Databases” tab to create a new database.

In the "Databases" tab, go ahead and choose the name of your website's database for the name of the database in MAMP.

If you don’t remember the name of your websites database you can find it in the "mwp_db" folder you saved earlier in step one. Look for the “.sql” file in that folder, that’s your database.

Don’t worry about choosing a “Collation”, it will automatically be assigned. After you’ve named your database click “Create” to get your database created.

Now you have a new database for your website.

Next you need to import your websites actual database tables into the newly created, blank database you just created.

Before importing your database tables make sure you have your newly created database selected. You should see "Server: localhost >> Database: yourdatabasename, or something similar at the top of the window above the tabs that make up the navigation. See the image below:

This tells you which database you're currently in. This is important, especially if you have more than one database. You don't want to import database tables into the wrong database.

Once you've selected your database you will see that you're currently in the "Structure" tab. You need to select the "Import" tab.

Now you're going to import your websites database. Remember the file you set aside earlier before adding your site files to the document root in MAMP in step one called "mwp_db"? Well, now you need the ".sql" file in that folder.

With the "Import" tab selected you will see a screen that looks like this:

Under "File to import:" you need to browse your computer for the database file in the "mwp_db" folder, the ".sql" file. Once you've selected the file you don't need to change anything else on the page, the default settings are fine. Scroll down and click "Go". It will take a few seconds for the database file to upload.

Step 4: Potential Problems

Import Issues For Large Databases

Depending on the size of your database it might take a few minutes for the import to complete. One thing to take note of is that the default upload size of phpMyAdmin is 32MB. This can cause an issue if your website’s database is larger than 32MB, such as 170MB for example. Luckily I have a solution for that issue.

If you run into this problem and phpMyAdmin tells you your database is too large you can change the defaults yourself. You will need to navigate to your MAMP folder /Applications/MAMP/bin/php/php7.1.8/conf/ and open the "php.ini" file with your favorite text editor.

Note that /php7.1.8/ is the version of PHP 7 setup in MAMP that you are going to test. Since this may not be the same the version you want to test, just make sure you choose the correct PHP 7 version. Also the versions available might be different depending on which version of MAMP your running.

With the "php.ini" file open in a text editor you are going to change the values of the following variables:

post_max_size = 256M ; // Maximum amount of POST data that PHP will accept
upload_max_filsesize = 256M ; // Maximum allowed size for uploaded files
max_execution_time = 600 ; // Maximum execution time of each script, in seconds
max_input_time = 600 ; // Maximum amount of time each script may spend parsing request data
memory_limit = 512M ; // Maximum amount of memory a script may consume (8MB)

The variable post_max_size should be located on line 373, and upload_max_filesize should be located on line 481. Changing them to 256M should work. They just need to be larger than your database .sql file.

Note that for the variables max_execution_time, max_input_time, and memory_limit, these variables should be on lines 230, 231 and 232.

Also, for memory_limit, you need to change the size to an amount larger than your database file as well. That’s why I chose 512M.

Once you’ve changed the values for these variables you need to restart MAMP. You should be able to upload your database without any problems now.

Missing Tables

If you import your database and get an error notice about SQL syntax, etc., you may have some missing tables. You can look at your live database tables by opening up phpMyAdmin through your hostings cPanel and compare the tables to see if anything is missing.

But if you need a fix for this issue then you will need to export a copy of your database from your hostings cPanel.

Log into your hosting, go to your cPanel, and look for a section called "Databases" or something similar. You will see an option for "phpMyAdmin". Click on "phpMyAdmin". This is where you will be able to select your websites database. Select the "Export" tab and download your database. But, before you do, have a look at this article on WP Engine for some helpful tips to ensure you get all your tables when downloading your database.

Step 5: Setting Up Your Database for Local Usage

Once you've successfully imported your database tables into your new database, click on the "Databases" tab where you will see a list of all the databases you've added to MAMP. If this is the first database you've added, it will be the only one listed. Click on "Check Privileges" next to your database.

On the next screen click on "Add user account", which will take you to a screen that looks like this:

You're going to add the user for your database on this screen, so you'll need to navigate to your site files in MAMP, /Applications/MAMP/htdocs, and look for a file called "wp-config.php".

Open the file in your favorite text editor, mine is Sublime Text 2, and look for the "DB_USER" and the "DB_PASSWORD" variables. Enter those into the "User name" field and the "Password" field in phpMyAdmin. For "Host name", just enter "localhost", and leave the rest of the settings as they are. Then scroll down and click "Go".

On the next screen you will see this:

Last but not least, you will need to edit two lines within your database. Navigate back to the "Databases" tab and click on your database name. Scroll down and look for a table called "wp_options" and click on it. You'll see a list of table names like this:

You will need to edit two fields, "siteurl", which is highlighted above, and "home" which you may have to look for on the second page.

First click on "Edit" next to "siteurl" and replace the URL contained in "option_value" with "http:localhost:8888/mywebsite/", "mywebsite" should be the name of your website, and click "Go", which will take you back to the previous page.

Then, scroll down to where you see something like the image below and click on the next arrow to take you to the next page.

Look for "home" under "option_name and click on "Edit". Replace the URL contained in "option_value" with "http://localhost:8888/mywebsite/" as you did above, and click "Go".

That's it! You should have a working mirror image of your website.

Note, if you use custom permalinks you will need to change them to default in WordPress > Settings > Permalinks in order to prevent internal links within your local site from breaking. You can then change your permalinks back to their custom form at any time.

Testing Your Local Site

Now that you have MAMP setup, your site files in the document root folder in MAMP, /Applications/MAMP/htdocs, or whichever folder you chose as your document root, and your database imported to phpMyAdmin you are now ready to test your local install for compatibility with PHP 7.

If MAMP is still open and running make sure you have the correct version of PHP that you are going to test selected in the “PHP” tab in MAMP.

Then in your MAMP WebStart page click on My Website in the navigation bar. This will take you to a page that lists all the sites you have installed in your document root for MAMP. Click on the name of your site and your new local install will load in your browser, running PHP 7, and ready for testing.

Now you can check your entire site to make sure there aren’t any functionality or display issues, update anything that needs updating, and fix whatever issues arise, if any. Once you feel confident that your site is ready for PHP 7 you can update your hosting’s server to run PHP 7.

So how did your testing go? Hit any snags along the way? Are you ready for PHP 7? Let me know in the comments below. If you liked this article please rate it 5 stars!

comments powered by Disqus

About Me

Hi there. I'm Rachel Kay, a Web Developer, Illustrator, & Designer, whose hobby is to be creative and artistic, while freelancing as a Web Developer building creative, modern websites.