Okay, I have done this before, over 10 years ago. Here I am doing it again. There are plenty of guides around on the Internet that can help with this process. I am just making a note here:
- Zip up the whole document root directory. On CPanel’s File Manager, select all and then click on “Compress”.
- Export mysql database that corresponds to the WordPress website, and say you name the file as wp-db.sql. You can zip the file to make it smaller if you want.
- Transfer these two zip files to the new webserver, e.g. /var/www/html. You can use wget to copy the files from existing web server to the new web server.
- Unzip the files.
- At this point, you won’t be able to access your webpage yet. Because the mysql database records, from your website, need to be placed into the new mysql server. This requires that you create a new database on your mysql server. To do that run this command.mysql -u root -p
Type the master password, then type the following command.
CREATE USER ‘wordpress-user’@’localhost’ IDENTIFIED BY ‘your_password’;
Here replace wordpress-user and your_password with your username and password. You can refer to wp-config.php for the username and password you have used for accessing your WordPress mysql database in the previous set up.
Run this command to create a new database.
CREATE DATABASE ‘wordpress-db’;
Here replace wordpress-db with your database name, which again you can refer to wp-config.php in case you want to keep the same name.
Now grant full privileges for your database to the WordPress user that you created earlier.
GRANT ALL ON wordpress-db.* TO ‘wordpress-user’@‘localhost’;
Now flush the database privileges.
- Import the mysql database, that you unzipped earlier, into the new mysql server’s wordpress-db database you just created.mysql -u root -p wordpress-db < wp-db.sql
- To allow WordPress to use permalinks and .htaccess file run this command.sudo nano /etc/httpd/conf/httpd.conf
Find the section that starts with <Directory “/var/www/html”> using the scroll key of your keyboard.
Here replace “None” with “All”
Then save and exit the editor.
- You should now be able to access your website by typing in the IP address of your new web server. Next the DNS name servers need to be updated to point to the location of your new web server.