Move a Wordpress Website Manually

Revision as of 15:51, 27 April 2022 by Root (talk | contribs)

Manually moving a Wordpress Website to another server or another directory consists several similar steps.

Database

If moving to a different database server or changing the name of a database (for consistency or whatever);

Export the Database: Using phpMyAdmin, Select the database in the left pane, Export Tab, "Simple" Radio Button, Go Button, save it to a file, done.

Create a New Database: Use the following commands;

  • mysql -u WhatEverUserName -p
  • ...then press enter and type in the database password
  • CREATE DATABASE WhatEverDatabaseName;
  • GRANT ALL ON WhatEverDatabaseName.* TO 'WhatEverUserName'@'localhost' IDENTIFIED BY 'WhatEverPassword';
  • FLUSH PRIVILEGES;

...notice the semi-colon at the end of the above commands

Import the Database: Using phpMyAdmin, Select the database in the left pane, Import Tab, Browse Button to locate the exported file, Go Button (then wait). Possible issues can occur here if different PHP time variables aren't set correctly. Importing can also be done from the command line. Just noting that here, it's simple to solve, but not addressed here, so don't worry or get frustrated, just Google the error. Afterall, the original database still exists, so you haven't messed anything up.

Copy the Files and set / check Permissions

  • If moving the website to a different server: Make a copy of the Website Files;
    • tar -cvzf /WhatEverDestinationFileName.tar.gz /WhatEverPathToSource/*
    • De-Compress: gunzip WhatEverFileName.tar.gz, tar xf WhatEverFileName.tar
    • Copy the 'Zipped File' using one of the below methods
      • If Samba is set up, use Windows Explorer
      • rsync -vP WhatEverFileName UserName@URLorIPAddress:/WhatEverPath (rsync -vP switch is "verbose" and "progress meter")
    • Note: The .htaccess file can present a bit of an issue when "tarring", so check it and copy manually if needed.

OR

  • If moving to a different directory (it is assumed the root directory is /var/www/html, modifiy to suit your location);
    • cp -ax WhatEverSourceDirectory WhatEverDesitnationDirectory
  • Move or copy the saved database and website files to another server:
  • Check or Correct Permissions and Ownership
    • chown -R apache:apache WhatEverDirectoryName
    • find WhatEverFolderName -type d -exec chmod 755 {} \;
    • find WhatEverFolderName -type f -exec chmod 644 {} \;
  • If using Let's Encrypt SSL Certificates, move Certificates to the new server: /etc/letsencrypt/archive, live, renewal (there are symbolic links in the live directory): rsync -avzP /etc/letsencrypt/archive/ UserName@URLorIPAdddress:/etc/letsencrypt/archive/ (repeat for each directory, the "a" switch will preserve symbolic links, find . -type l -ls will display the symbolic links)
  • Change DNS Settings
  • Configure new Apache Configuration File
  • Configure any new directories necessary: Log Files for Apache, etc.
  • Upgrade WordPress or change PHP version if needed, the former recommended.
  • If any custom redirect files are used (redirect.html, redirect.php) to redirect HTTP to HTTPS, modify them

All of the above assumes the new server has the same services running like Apache, PHP, MariaDB / mySQL, etc.