Introduction Migrating a WordPress site from a local development environment to a live server can be a complex process, especially for those unfamiliar with how WordPress manages files and databases. This guide walks you through every step of the migration process, including common pitfalls, troubleshooting, and best practices.
Step 1: Back Up Your Website Files and Database
Before making any changes, always create a backup of your WordPress site, including both files and the database.
Backing Up Your Files
- Using cPanel File Manager or FTP:
- Navigate to the root folder of your local WordPress installation (e.g., htdocs/MyWordPress/ if using XAMPP).
- Compress all files into a .zip file and download them to your computer.
- If using FTP, use FileZilla to connect to your server and transfer files manually.
Backing Up Your Database
- Export Database from Local Server:
- Open phpMyAdmin (http://localhost/phpmyadmin/).
- Select your WordPress database and click “Export” (use the “Quick” option with SQL format).
- Download the .sql file to your computer.
Step 2: Upload Your Files to the Live Server
Using cPanel File Manager or FTP
- Log in to your hosting provider’s cPanel.
- Navigate to public_html/ or the appropriate directory for your domain.
- Upload and extract your .zip file.
- Ensure that the files are placed directly in the root directory (not inside a subfolder like /MyWordPress/, unless you intend to keep it there).
Step 3: Create and Import the Database
Creating a New Database in cPanel
- Go to MySQL Databases in cPanel.
- Create a new database and note the database name.
- Create a database user and assign it full privileges.
- Save the database name, username, and password for later.
Importing Your Database
- Open phpMyAdmin from cPanel.
- Select the new database.
- Click Import and upload the .sql file from your backup.
- If you encounter errors, check for incompatible SQL modes and adjust accordingly.
Step 4: Update wp-config.php File
Editing wp-config.php
- Open the wp-config.php file in your WordPress directory.
- Update the database details:
- define(‘DB_NAME’, ‘your_new_database’);
- define(‘DB_USER’, ‘your_database_user’);
- define(‘DB_PASSWORD’, ‘your_database_password’);
- define(‘DB_HOST’, ‘localhost’); // Usually localhost, but some hosts require a different value.
- Save and upload the updated file to the server.
Step 5: Fix URLs and Links
After migration, URLs often still point to the localhost version. You must update these links.
Using phpMyAdmin to Update URLs
- Open phpMyAdmin and select your WordPress database.
- Run the following SQL query to update site URLs:
- UPDATE wp_options SET option_value = ‘https://yourdomain.com’ WHERE option_name = ‘siteurl’ OR option_name = ‘home’;
Using a Search and Replace Tool
Alternatively, use a plugin like Better Search Replace to update URLs in all database fields, including post content and metadata.
Step 6: Configure Permalinks and Fix 404 Errors
Resetting Permalinks in WordPress Dashboard
- Log into WordPress admin (yourdomain.com/wp-admin).
- Go to Settings > Permalinks.
- Select your preferred structure and click Save Changes (even if it’s already selected).
Fixing .htaccess Issues
- If pages still return 404 errors, check for an .htaccess file in the root directory.
- If missing, create a new .htaccess file with the following default WordPress rules:
- # BEGIN WordPress
- RewriteEngine On
- RewriteBase /
- RewriteRule ^index\.php$ – [L]
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule . /index.php [L]
- # END WordPress
- Save and upload the file, then try reloading the website.
Step 7: DNS & Domain Propagation
If you are also migrating to a new domain, DNS settings must be properly configured.
Checking DNS Settings
- Verify that your domain is correctly pointing to your hosting provider’s nameservers.
- Use a DNS checker (https://dnschecker.org/) to confirm the propagation status.
- If mismatched NS records are found, update them in your domain registrar’s panel.
Step 8: Final Testing and Troubleshooting
Common Issues & Fixes
- White Screen of Death:
- Enable debug mode in wp-config.php (define(‘WP_DEBUG’, true);).
- Incorrect Image URLs:
- Use a plugin like “Velvet Blues Update URLs” to fix media links.
- Cannot Log Into Admin Panel:
- Reset password via phpMyAdmin:
- UPDATE wp_users SET user_pass = MD5(‘newpassword’) WHERE user_login = ‘admin’;
Leave a Reply