Cómo migrar tu sitio Wordpress de un hospedaje compartido a una instancia SSD
As your website’s traffic grows and your reader/viewer base increases, you will eventually outgrow your shared hosting plan and consider migrating to a VPS.
In order to migrate your WordPress site while using the same domain, you should consider the following aspects:
- The database which consists of the site's architecture and text content,
- Files, including WordPress plugins, themes, and uploaded pictures, video and so on, and
- DNS records for specifying the hosting location.
This tutorial will cover the process of migrating a WordPress site from shared hosting to a Vultr VPS.
- An existing WordPress site where the core files are unmodified.
- An existing Vultr instance with a WordPress one-click app as the OS.
- An existing installation of WordPress on the Vultr instance that has been configured and is accessible via http://[[your-server-ip]/wp-admin.
- A sudo user with which you are logged in to the instance.
Step 1: Backup and download the WordPress database on the shared host
Usually, the shared host vendor provides you the ability to export your MySQL databases in the control panel or some database administration tool. Anyway, you need to export your whole WordPress database into your Web directory for download. Let's say the exported database file is
wordpress.sqlwhich is sitting in the base directory of the Web directory on the shared host.
Copy the database backup file to you server from your SSH terminal. Make sure that the permissions of the file is 644 to avoid the 403 forbidden error.
cd ~ wget http://www.yourdomain.com/wordpress.sql
Additionally, make sure to prepare the database name, database username, and database password for future use.
Notice: To prevent unauthorized access, the database backup file in the Web directory should be removed as soon as you finish the transmission. Additionally, you can use a random name/string as the file name which greatly reduces the possibility of unauthorized access to the file. Regardless, the file should be removed immediately after it’s been downloaded into your Vultr instance.
Step 2: Backup and download necessary files on the shared host
You only need to backup the entire
wp-contentdirectory and some manually added files, such as
favicon.ico, in the base directory of the Web directory. Let's say you have added the whole "wp-content" directory and all of these files into an archive file named
files.tar.gzwhich is also at the base directory of the Web directory.
Copy the archive file to you server from your SSH terminal. Again, be sure that the permissions of the file is 644.
Delete this archive file in the Web directory after the transmission.
Step 3: Update your VPS and the WordPress program
Update your system with Yum:
sudo yum update -y
Then update your WordPress installation to the latest version from the WordPress Dashboard.
Step 4: Rebuild the WordPress database on the VPS
In order to restore you WordPress site on the Vultr VPS, you need to rebuild the Vultr WordPress database, in other words, you need to delete all of its tables and import the former database backup.
Display the default MySQL credentials of Vultr one-click WordPress app:
sudo cat /root/.my.cnf
Use the credentials on the screen to log in MySQL shell:
mysql -u root -p
Find the database whose name consists of
wpand 7 digits, and then switch to use it. Say it is
SHOW DATABASES; USE wp9968857;
Optional: You can generate table dropping commands for review:
Select CONCAT( 'drop table ', table_name, ';' ) FROM information_schema.tables Where table_name LIKE 'wp_%';
Use the following commands to delete the 12 tables in the database wp9968857:
USE wp9968857; DROP TABLE wp_commentmeta; DROP TABLE wp_comments; DROP TABLE wp_links; DROP TABLE wp_options; DROP TABLE wp_postmeta; DROP TABLE wp_posts; DROP TABLE wp_term_relationships; DROP TABLE wp_term_taxonomy; DROP TABLE wp_termmeta; DROP TABLE wp_terms; DROP TABLE wp_usermeta; DROP TABLE wp_users;
While still in the MySQL shell, import the MySQL backup file into the newly created database:
SET NAMES 'UTF8'; SOURCE ~/wordpress.sql EXIT;
Step 5: Restore backup files
In order to restore the backup files, you need to unzip the
files.tar.gzfile, set proper permissions for each file and directory, and move them back to proper locations.
Unzip the backup file to your home directory:
cd ~ tar -zxvf ~/files.tar.gz -C ~
wp-contentdirectory and the manually added file "favicon.ico" should sit in your home directory.
To prevent permission errors, the whole
wp-contentdirectory and the file
favicon.icoshould belong to
sudo chown -R nginx:nginx wp-content sudo chown nginx:nginx favicon.ico
Also, the permissions of the
wp-contentdirectory and its every sub directory should be set to 755, the permissions of every file should be set to 644:
sudo chmod 755 wp-content cd wp-content find ./ -type d -print | sudo xargs chmod 755 find ./ -type f -print | sudo xargs chmod 644 cd ~ sudo chmod 644 favicon.ico
Move them back to the Web directory
sudo mv /var/www/html/wp-content /var/www/html/backup-wp-content sudo mv ~/wp-content /var/www/html/wp-content sudo mv ~/favicon.ico /var/www/html/favicon.ico
Restart the server:
sudo shutdown -r now
Now, you can have a look at your migrated site from http://[your-server-ip]/. Remember to use the former WordPress credentials to log in. The WordPress credentials that you setup during deploying the VPS have been erased and no longer exist.
If there are texts or links related to your former IP address in the contents of your WordPress site, you need to correct them manually.
Step 6: Modify DNS records
At last, you need to modify the DNS A records of your domain, replace the IP of the shared host with the IP of the Vultr VPS you are using. After the modifications becoming effective, you can visit your new WordPress site using your domain name.
This concludes our tutorial. Thank you for reading and Happy blogging!
Var dette svaret til hjelp?
Les også disse
PHP y paquetes relacionados son los componentes más utilizados cuando se implementa un servidor...
ConfigServer Security & Firewall (CSF) es un firewall de inspección de paquetes con estado...
Después de restaurar un snapshot en una nueva máquina, puede encontrar problemas causados...
Para restablecer la contraseña root de su servidor, tendrá que arrancar en modo de usuario único....
Bifurcado de MySQL, MariaDB ha sido conocido por ser un reemplazo que trae mejoras y...
Powered by WHMCompleteSolution