Backing up a WordPress website and transferring it to a different server under a different domain involves several key steps. This process can be split into three main phases: Backup, Transfer, and Restoration & Configuration. Here's a detailed guide:
- Log into the server where your WordPress site is hosted.
- Access the MySQL or MariaDB database using a command like:
mysql -u username -p
- Use the following command to export your database to a SQL file:
mysqldump -u username -p database_name > database_name.sql
- This will prompt for the database password and create a database_name.sql
file with all your WordPress data.
- Using SSH, navigate to the root directory of your WordPress installation.
- Compress the WordPress directory to a ZIP file (or tar.gz if preferred) to make the transfer easier:
tar -czvf yoursite_backup.tar.gz /path/to/your/wordpress/
- This command creates a compressed archive of your entire WordPress directory, including themes, plugins, uploads, and core files.
- Securely copy the database and file backups to the new server using scp
:
scp yoursite_backup.tar.gz username@newserver_ip:/path/to/destination/
scp database_name.sql username@newserver_ip:/path/to/destination/
- Replace username
, newserver_ip
, and /path/to/destination/
with the appropriate credentials and path on the new server.
- SSH into the new server.
- Navigate to the directory where you want to install WordPress.
- Unpack the WordPress files:
tar -xzvf yoursite_backup.tar.gz
- Log into MySQL or MariaDB:
mysql -u root -p
- Create a new database:
CREATE DATABASE new_database_name;
CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'new_password';
GRANT ALL PRIVILEGES ON new_database_name.* TO 'new_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
- Import your database data:
mysql -u new_user -p new_database_name < /path/to/database_name.sql
- Edit the wp-config.php
file to update the database name, user, and password.
vim wp-config.php
- Change the DB_NAME
, DB_USER
, and DB_PASSWORD
to the new values.
- You can update the site URL directly in the database:
mysql -u new_user -p
- Use SQL commands to change the site URL:
USE new_database_name;
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsite.com', 'http://www.newsite.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldsite.com','http://www.newsite.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldsite.com', 'http://www.newsite.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldsite.com','http://www.newsite.com');
- Log into the WordPress admin panel on the new domain.
- Go to Settings -> Permalinks and simply click 'Save Changes' to flush rewrite rules.
- Browse the site to make sure everything is functioning correctly. Check for broken links and ensure all media loads.
- Check the .htaccess
file for any hard-coded paths that might need updating.
- Ensure that all plugins and themes are working correctly. Sometimes, manual reactivation is necessary.
This method provides a comprehensive approach to moving a WordPress site to a new domain and server. Remember to check all functionality and security settings after the migration to ensure the site operates smoothly on its new host.