How to Manually Migrate a WordPress Website from One Host to Another
Migrating a WordPress website from one host to another can seem daunting, but with a step-by-step guide, the process becomes manageable. In this tutorial, we’ll walk through the process of migrating a WordPress site hosted on an AWS EC2 instance to an Azure Virtual Machine (VM). While there are migration plugins available, they are often not reliable and can lead to issues such as incomplete migrations or corrupted data. These steps can be applied to any WordPress migration, regardless of the hosting environment, ensuring a smooth and error-free transition.
Pre-Migration Steps on the Destination Host
1. Prepare the Destination Host
- • Log in to the destination VM where the WordPress site will be hosted.
- Install the necessary prerequisites for WordPress:
- PHP
- MariaDB/MySQL
- Apache2/Nginx
2. Install WordPress
- Download and install WordPress on the destination host.
- Apache to serve the WordPress site
- Create a new Apache site configuration for WordPress.
- Enable the site with:
sudo a2ensite wordpress - Enable URL rewriting:
sudo a2enmod rewrite - Disable the default Apache site:
sudo a2dissite 000-default - Reload Apache to apply changes:
sudo service apache2 reload
3. Set Up the Database
- Create a new database and user with appropriate permissions
sudo mysql -u root
In the MySQL shell, run the following commands:
CREATE DATABASE wordpress;
CREATE USER ‘wordpress’@’localhost’ IDENTIFIED BY ‘<your-password>’;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON wordpress.* TO
‘wordpress’@’localhost’;
FLUSH PRIVILEGES;
quit; - Enable MariaDB/MySQL to start on boot:
sudo systemctl enable mysql
4. Configure WordPress
- Navigate to the WordPress directory and copy the sample configuration file:
cp wp-config-sample.php wp-config.php - Update the wp-config.php file with the database name, username, and password.
- Replace the authentication salts using a secret key generator from WordPress:
- Visit https://api.wordpress.org/secret-key/1.1/salt/.
- Replace the below lines in wp-config.php with the authentication salts. (This address is a randomizer that returns completely random keys each time it is opened. This step is important to ensure that your site is not vulnerable to “known secrets” attacks.) define( ‘AUTH_KEY’, ‘put your unique phrase here’ );
define( ‘SECURE_AUTH_KEY’, ‘put your unique phrase here’ );
define( ‘LOGGED_IN_KEY’, ‘put your unique phrase here’ );
define( ‘NONCE_KEY’, ‘put your unique phrase here’ );
define( ‘AUTH_SALT’, ‘put your unique phrase here’ );
define( ‘SECURE_AUTH_SALT’, ‘put your unique phrase here’ );
define( ‘LOGGED_IN_SALT’, ‘put your unique phrase here’ );
define( ‘NONCE_SALT’, ‘put your unique phrase here’ );
- Save and close the file.
5. Verify Installation
- Open the site’s URL (public IP, hostname, or localhost) and complete the WordPress setup
Migration Steps from the Source Host
1. Export Files and Database
- Log in to the source host.
- Compress the wp-content directory:
zip -r wp-content.zip wp-content - Export the wp-config.php file.
- Export the database (Change the command based on the location and name of the database, in our case the database name is bitnami_wordpress and the location is /bitnami/mariadb/data on the source machine):
mysqldump -u your_username -p bitnami_wordpress > bitnami_wordpress.sql
2. Transfer Files to the Destination Host
- Use tools like WinSCP or SCP to transfer the wp-content.zip, wp-config.php, and bitnami_wordpress.sql files to the destination host.
3. Import the Database
- Move the .sql file to the MySQL data directory (e.g., /var/lib/mysql).
- Update file permissions:
sudo chmod 644 bitnami_wordpress.sql
sudo chown -R mysql:mysql /var/lib/mysql/bitnami_wordpress
sudo chmod -R 755 /var/lib/mysql/bitnami_wordpress - Import the database:
mysql -u root -p wordpress < bitnami_wordpress.sql - Update the WordPress site URL in the wp_options table:
UPDATE wp_options
SET option_value = ‘http://Your_Site_Address’
WHERE option_name IN (‘siteurl’, ‘home’);
Replace Your_Site_Address with the new IP address or hostname.
4. Restore the wp-content Directory
- Extract the wp-content.zip file to the WordPress directory:
unzip wp-content.zip -d /path/to/wordpress
5. Verify and Troubleshoot
- Visit the new site’s URL to ensure it is working as expected.
- If you encounter a critical error, rename the plugins directory and reactivate plugins
individually to identify issues.
Post-Migration Tasks
1. Configure SSL
- Use a tool like Let’s Encrypt to secure the site with an SSL certificate
2. Update DNS Records
- Point the domain’s DNS records to the new host’s IP address.
Conclusion
Migrating a WordPress website manually ensures full control over the process and avoids
potential issues that can arise with automated tools. By following this comprehensive guide,
you can ensure a smooth transition, maintaining your website’s integrity and functionality. If
you found this guide helpful, share it with your network to help others with their WordPress
migration journey
No Comments