Running WordPress locally on your computer is a great way to develop and test your site before making it live. Here's a step-by-step guide:
Requirements
-
Web Server Software: Apache or Nginx.
-
Database: MySQL or MariaDB.
-
PHP: A version compatible with WordPress (PHP 7.4 or newer is recommended).
-
Local Server Tools:
- Install one of the following to simplify setup:
-
XAMPP (Windows, macOS, Linux)
-
Local by Flywheel (Windows, macOS)
-
WAMP (Windows only)
-
MAMP (macOS and Windows)
Step 1: Download and Install a Local Server
Using XAMPP (example)
- Download XAMPP from https://www.apachefriends.org/.
- Install XAMPP and ensure Apache, MySQL, and PHP are included.
- Launch the XAMPP Control Panel and start:
-
Apache: The web server.
-
MySQL: The database server.
Step 2: Download WordPress
- Visit https://wordpress.org/download/.
- Download the latest WordPress .zip file and extract it.
- Place the extracted folder into the htdocs directory of XAMPP:
- For Windows: C:xampphtdocswordpress.
- For macOS: /Applications/XAMPP/htdocs/wordpress.
Step 3: Set Up the Database
- Open your web browser and go to http://localhost/phpmyadmin.
- Click Databases at the top.
- Enter a name for your database (e.g., wordpress) and click Create.
- No need to add tables; WordPress will handle this during installation.
Step 4: Configure WordPress
- Open your browser and visit http://localhost/wordpress.
- Follow the on-screen instructions:
- Select your language and click Continue.
- Enter the database details:
-
Database Name: The name you created in phpMyAdmin (e.g., wordpress).
-
Username: root (default for XAMPP).
-
Password: Leave blank (default for XAMPP).
-
Database Host: localhost.
-
Table Prefix: wp_ (default; can be changed for security).
- Click Submit, then Run the Installation.
- Fill in site details:
- Site Title
- Admin Username and Password
- Admin Email
- Click Install WordPress.
Step 5: Access WordPress Locally
- Go to http://localhost/wordpress to view your site.
- To access the admin dashboard, go to http://localhost/wordpress/wp-admin and log in with the credentials you created.
Tips for Development
-
Enable Debugging: In the wp-config.php file, set:
define( 'WP_DEBUG', true );
Copy after login
-
Custom Themes or Plugins: Place them in the wp-content/themes or wp-content/plugins folder, respectively.
-
Backup Regularly: Use tools like Duplicator or manually back up the database and wp-content folder.
You're now set up to run WordPress locally! Let me know if you need assistance with any of these steps.
The above is the detailed content of Running WordPress locally on your computer. For more information, please follow other related articles on the PHP Chinese website!