目录
Step 1: Download and Install MAMP on your PC
Step 3: Create a New Database for Your WordPress Site
Step 4: Download WordPress to your PC
Step 5: Move WordPress into MAMP htdocs
Step 6: Install WordPress Locally on your Windows PC
Step 9: Copy live contents in public_html to htdocs
Step 10: modify wp-config.php in htdocs
Step 1: Download and Install MAMP on your PC
The first step in the process of installing WordPress locally is to create a local hosting environment on your Windows PC. To do this, we recommend using MAMP.
MAMP (Mac, Apache, MySQL, PHP) is a free and premium local server environment that can be installed on the macOS and Windows operating systems. The free version of MAMP provides all the tools you will need to run WordPress on your PC for testing and development purposes.
MAMP PRO comes with extra features, allowing you to create a separate hosting environment for each web project and import existing WordPress sites from live servers. Once your design work is completed, you can also publish projects directly from MAMP PRO to your live server.
To install MAMP, navigate to the Download page on MAMP’s website and select the MAMP and MAMP PRO 4.2.0 (Windows) option.
Now, simply follow the pop-up instructions to install MAMP on your computer.
Step 2: Run MAMP on your PC
Once installed, you need to run MAMP on your PC. Click on the MAMP icon which will now be present on your desktop and select Start Servers.
After Apache Server and MySQL Server have been activated, click the Open WebStart Page option. The local homepage of your new MAMP install will now open within your browser, telling you that MAMP has been successfully installed on your computer.
If you scroll down the page, you will find the details of your MySQL connection, including your username and password. You will need this information later on when you connect your local database to WordPress, so take note.
Step 3: Create a New Database for Your WordPress Site
The next step is to create a new database in which WordPress will store all the back-end data related to your site, such as posts, pages, options, settings, and menus. You need to create the database in the phpMyAdmin application which is included in your MAMP install. To open the program, select the Tools > phpMyAdmin option in the top menu bar of your MAMP homepage.
In the phpMyAdmin application, click the Databases menu and find the Create database section on top of the page. Choose a name for your new database, set the collation to utf8_general_ci, and click the Create button. In this case, I created a database 'wp_mysql'.
Your new database has now been created.
Step 4: Download WordPress to your PC
You next need to download WordPress onto your computer. Go to the Download page of WordPress.org and click the Get WordPress > Download and install button.
Once WordPress has downloaded to your Windows PC, you need to unzip the folder and extract the files.
Step 5: Move WordPress into MAMP htdocs
Now, you need to move WordPress into the htdocs folder of your MAMP install. Copy the unzipped WordPress folder and navigate to MAMP > htdocs; you should find it in your root folder (it’s usually the C drive). Paste the contents of WordPress folder into the htdocs folder.
The name of your local site will be http://localhost
Step 6: Install WordPress Locally on your Windows PC
Install WordPress on your local server. Type the URL of your local WordPress site into your browser’s address bar. I used the http://localhost URL.
Now, follow the instructions appearing on the screen. First, select the language of your choice.
You will then need to fill in some information about the new database you have created. You will need to define…
- Database Name – This is the name you chose when setting up the new database for your test site in phpMyAdmin. For instance, I used wp_mysql as database name in our example.
- Database Username and Password – Both the username and password are root. This info can be found on the MAMP installation page in the MySQL section (as discussed earlier).
- Database Host – This is localhost. Again, this info can be found on the MAMP installation page.
- Table Prefix – Leave this as the default wp_.
Now, you are ready to install WordPress on your local server. To do so, click the Run the installation button.
You will need to provide some details about your test site. These settings can be changed later on if needed, so don’t worry too much about your site title, username, and other details at this stage. Then click on Install WordPress.
You can now log into your WordPress test site using the localhost/wp-admin URL
Step 7: Import .sql file
Export the sql dump from your live site, and:
- Open the .sql file and replace all your live website domain address with local host (e.g., replace http://edwardwangcq.com with http://localhost in my case)
- From dos command line, run following:
cd c:\MAMP\bin\mysql\bin c:\MAMP\bin\mysql\bin>mysql.exe --host=localhost -uroot -proot –default-character-set=utf8 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1419 Server version: 5.7.24 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; use wp_mysql; source C:\MAMP\htdocs\i6205817_wp1_localhost.sql
-
When you have new .sql file that need to be imported, not necessary to delete existing tables of database, just import directly would be fine.
Step 8: Backup htdocs
Step 9: Copy live contents in public_html to htdocs
Download the live contents in public_html from your site, and copy them into htdocs directory. Replace all the files that are the same
For example, I have backup of live site at 'C:\ecosys\Projects\web\web_backup_20210407\backup-edwardwangcq.com-4-7-2021\backup-4.7.2021_06-44-42_mu4nf80a19ei\backup-4.7.2021_06-44-42_mu4nf80a19ei\homedir\pubic_html\', just copy & paste contents in this public_html to 'C:\MAMP\htdocs' and whenever prompt, just accept all replacement.
One error I hit was:
I have another backup of live set at 'C:\ecosys\Projects\web\web_backup_20210421\backup-edwardwangcq.com-4-20-2021\public_html'. After copy & paste the contents in public_html to 'C:\MAMP\htdocs', always hit following error when open the 'http://localhost':
Then, I diff the 2 public_html folder:
1) C:\ecosys\Projects\web\web_backup_20210421\backup-edwardwangcq.com-4-20-2021\public_html (backup of home directory on US Domain)
2) C:\ecosys\Projects\web\web_backup_20210421\backup-edwardwangcq.com-4-20-2021\backup-4.20.2021_21-09-21_mu4nf80a19ei\backup-4.20.2021_21-09-21_mu4nf80a19ei\homedir\public_html (backup-4.20.2021_21-09-21_mu4nf80a19ei is backup of whole website from US domain and it is saved in my home directory)
And find that there is one difference and only difference of the 2 folders is, the file '.htaccess' of the item 1) has following codes:
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php56___lsphp .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Then, I comment out these codes, and the issue disappeared!
Step 10: modify wp-config.php in htdocs
(otherwise, hit error establishing a database connection)
/** The name of the database for WordPress */
define( 'DB_NAME', 'wp_mysql' );
/** MySQL database username */
define( 'DB_USER', 'root' );
/** MySQL database password */
define( 'DB_PASSWORD', 'root' );
Step 11: Edit the menu
In my case, the website menu setting lost in localhost, just edit it after logging into wp-admin
Reference
How to Install WordPress Locally on Windows PC (Using MAMP)
How to Move Live WordPress Site to Localhost? – WebNots
Import Large MySQL Database in phpMyAdmin in MAMP – WebNots
How to Install WordPress on Mac Using MAMP - Qode Interactive
How to Install WordPress on Local Mac Using MAMP? – WebNots
<end>