How to Copy a Live WordPress Website to a Local Mac with cPanel, MAMP and Hosts File Redirection
It is normally not a problem to make minor updates and changes to a live WordPress website online such as making blog posts. However if you need to perform more substantial updates and changes to a WordPress website you risk the possibility of bringing down the entire site if something goes wrong. You also risk the possibility of disrupting current users while performing significant updates and changes. Therefore it is often advisable to copy a live WordPress website to a local Mac (or PC) to perform significant updates, changes or development. In this blog post I’ll show how to copy a live WordPress website to a local Mac.
Backup your Live WordPress Website to Your Local Mac
The first step in how to copy a live WordPress website to a local Mac is to make a backup copy of your live WordPress Website to your local Mac. This is something you should be doing periodically anyway to keep local backup copies of key milestones for your website. There are a number of different plugins you may use to do this from within WordPress itself. But if your web hosting provider uses cPanel to manage your account you can simply download a backup of your website using cPanel itself without cluttering up your WordPress installation with more plugins. cPanel allows you to easily backup your entire home folder which includes all WordPress content including WordPress itself, it’s current configuration, all plugins, themes and uploads. cPanel also allows you to backup your WordPress database which includes various settings, posts, pages and other content.
- Log into your host account’s cPanel
- Go to the Backup section
- Click on the Home Directory button under Download a Home Directory Backup
- Click on the name of your database under Download a MySQL Database Backup
dreamlight_wordpress in this case
- Double-click the downloaded home directory backup archive in the Finder to decompress all the files.
- Copy the entire public_html folder (which includes all WordPress files) to a local folder on your Mac. In this cas I I copied it to a Sites folder in my user directory (~/Sites). It’s important to copy the entire public_html folder rather than just the contents of the folder because you want to also copy the hidden .htaccess file inside that folder. If you just copy the contents it won’t copy that hidden file and you’d have to recreate it or copy it manually using the terminal. Copying the folder saves some steps.
- Rename the copied public_html folder to the domain name of the live site, in my case DreamLight.com.
Download and Install MAMP (My Apache, MySQL, PHP)
- Download MAMP from: https://www.mamp.info
MAMP (My Apache MySQL PHP) Enables running local servers of Apache (& Nginx) MySQL and PHP to run WordPress locally on Mac or Windows. You can use the free MAMP version for one site at a time or upgrade to MAMP PRO for multiple sites and much more powerful features.
- Click the MAMP Free Download button
- Download MAMP (& MAMP PRO)
- Install MAMP
- Click the MAMP icon in Launchpad to launch it
- Open MAMP Preferences
- In MAMP Preferences Ports tab click Set Web & MySQL ports to 80 & 3306
- In MAMP Preferences Web Server tab set Document Root to the folder that you copied from the public_html folder, in this case: userx > Sites > DreamLight.com
Create a New Local MySQL Database in phpMyAdmin
- With servers running in MAMP, click on Open WebStart Page
- In the Tools menu select phpMyAdmin
- This launches phpMyAdmin
- Under Create database type the same database name as the database you downloaded from the live site
- Leave Collation menu alone. It will be set during WordPress installation
- Click the Create button
- The new database appears in sidebar list
- Then go to the Import tab
- Click the Browse button and select the database that you had downloaded from the live site with the same name as the new database you just created
- Finally scroll down and click the Go button. This may take a while if the database is large.
- When the import finishes you should receive a message stating: Import has been successfully finished
Add a New Local MySQL User
We’re almost done with how to copy a live WordPress website to a local Mac. WordPress needs to know the name of the database along with a username and password to access the database. This information is stored in the wp-config.php file.
Open the wp-config.php file that you copied along with the live site files and locate the following lines which show your database username and password. [NOTE: Database/Username/Password displayed here have been changed for security purposes and is shown here for sample purposes only.]
// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
/** MySQL database username */
/** MySQL database password */
If you create a matching username/password locally then you don’t need to edit this file and can more easily copy the site to/from the live site without having to edit settings all over the place.
- In phpMyAdmin click on the Databases tab
- Click on the Check privileges link next to the WordPress database
- Then click Add user account in the New section at the bottom
- Enter the User name and Password from the wp-config.php file
Redirect Live Website Domain Name to Localhost
Once you know how to copy a live WordPress website to a local Mac you can redirect the domain name to access it. In order to access the new local copy of the website using the same domain name as the live website we’ll redirect the domain name to point to localhost on your local computer. This won’t affect what anyone else sees when they use the domain name from other computers. They’ll still go to the live website online. But when you use the domain name on your local computer you will see your local copy of the website instead. This will also mean you won’t need to change any URLs that may be in your database.
Here’s an article about how to edit the hosts file on Mac OS X. [One caveat about the process. If you use TextEdit to edit the file first open TextEdit’s preferences and in the Open and Save tab turn off the checkbox for Add “.txt” extension to plain text files. The hosts file won’t work if it’s named hosts.txt instead instead of just hosts.]
- Add a line like this (using the domain name you wish to redirect to your localhost):
Later when you want to go back to using the domain name to access the live site again just comment out the line you added in your hosts file by adding a number sign (#) to the beginning of the line using the same process.
DreamLight Can Design a Custom WordPress Web Site for You
Now that you know how to copy a live WordPress website to a local Mac you may want to hire a developer. If you are looking for a WordPress developer DreamLight can develop a custom WordPress website for you. We will work closely with your marketing team to update your existing Web site that may be outdated or to design a brand new custom WordPress Web site. We design all our custom WordPress Web sites to be fully responsive. This means the overall design layout automatically re-flows on-the-fly to take best advantage of all modern mobile devices. We can also create a wide range of integrated branded marketing content for your Web site to help it really stand out, including: 2D/3D digital design, illustration, animation, interactive multimedia or application development.
Contact us for more information about designing a custom WordPress Web site or to explore your specific needs.