Migration of WordPress website to another web server

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:

  1. Zip up the whole document root directory. On CPanel’s File Manager, select all and then click on “Compress”.
  2. 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.
  3. 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.
  4. Unzip the files.
  5. 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.

    FLUSH PRIVILEGES;

    Exit mysql

    exit

  6. 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
  7. 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.

    <Directory “/var/www/html”

    AllowOverride None

    ….

    </Directory>

    Here replace “None” with “All”

    AllowOverride All

    Then save and exit the editor.

  8. 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.

Transferring web hosting service

It’s been a while since I last blogged. This time it’s about time to renew my web hosting service. At this current economic climate, USD200 for two years of service seems like a lot now. I have gone through web hosting service provider change for a number of times. But I still managed to get the DNS wrong, somehow. It should be a simple straightforward copy from the previous hosted zone file to the new service.

Okay, for my own record, as well as for others as well I guess, I have complete control over my web server now. I always have about two websites to manage. But as I figured out lately, it is called name-based virtual hosting that I have been using. So web access to my website will be based on domain name, not IP address. Because I have more than one websites hosted based on just the one IP address, accessing the IP address would not return me the desired webpage. The virtual host configuration is such that access, based on domain name, will get served documents from the document root as stated in the configuration. Okay this is clear to me now.

However, when managing my hosted zone, for domain name translation, I used a CNAME record for www (i.e. www.mylearningdiary.com) that pointed to the IP address of my web server.  That gave me a NXDOMAIN error, or non-existent domain error, everywhere. I initially thought that was to do with propagation delay after switching the DNS, at the registrar, to point to the new domain name servers. This is well known, so I patiently waited, and checked, and tested. But still couldn’t access my website. After a day or two, I trawled the Internet, and then started using dig, a network administration command-line tool for querying the DNS, which I have used before long time ago, to check what was going on. Dig is more helpful than nslookup, that it not only showed me the error, but it also showed me that I actually got the IP address returned when querying for the www CNAME record. That was useful enough for me to know that my DNS servers were responding to the CNAME query, just not good enough for me to reach my website. Instead of IP address, the domain name, i.e. mylearningdiary.com, should be used for the CNAME record.

Now the website is finally back up running again,  I need to try setting up the mail forwarding. Hopefully without me having to set a mail server.